'How to get id of parent tables which haven't any foreign key with another table
I have a structure of a table have many fields
| table_id | name_table | name_filed | PK | FK |
|---|---|---|---|---|
| 1 | person | id | pk | |
| 1 | person | name | ||
| 1 | person | age | ||
| 2 | dog | id | pk | |
| 2 | dog | name | ||
| 2 | dog | owner | fk | |
| 3 | phone | id | pk | |
| 3 | phone | name | ||
| 3 | phone | owner | fk |
How to get id(s) of parent tables which haven't any foreign key with another table in this case expected result is 1
I've tried
select distinct table_id from tables_structure where fk!=''
Also I've tried with group by
select table_id from tables_structure where fk!=''
group by table_id
having fk!=''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
