> For the complete documentation index, see [llms.txt](https://lauradang.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lauradang.gitbook.io/notes/databases/sql-commands/foreign-key-commands.md).

# Foreign Key Commands

### Show foreign key entries

```sql
SELECT * FROM table1 A 
INNER JOIN table2 B 
ON A.foreign_key_field = B.foreign_key_field
WHERE B.some_field = 1
```

### Get last inserted id for foreign key

```sql
SELECT LAST_INSERT_ID()
```
