I've got a simple join over a primary and foreign key... but I need to include a row from the parent table in the results for each primary key as a sort of header row for the children. For instance, I have two tables,
parents
ID | Name
0 | FOO
1 | BAR
2 | ASD
children
ID | Name | ParentID
10 | baz | 0
11 | zap | 0
12 | zam | 1
13 | maz | 1
I'd like to make a view that returns
ParentID | ChildID | Name | isChild
0 | | FOO | False
0 | 10 | baz | True
0 | 11 | zap | True
1 | | BAR | False
1 | 12 | zam | True
1 | 13 | maz | True
2 | | ASD | False
The data structure doesn't make much sense but it's populating 3rd party software and that's the only format option. Right now I'm hitting the database with an additional query for each parent. I imagine pulling it into one query would be more efficient, I've only got a few hundred parents
Thanks!
LEFT JOIN
). Simple queries are usually best handled on Stack Overflow; this site is meant for more specialized questions regarding database setup and configuration, optimization, and complex queries.