![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Getting John's brother and sisters without involving Adam in da query ------------------------------------------------------------------------- select P2.name, P2.sex from person P2 inner join link on P2.id = link.parent inner join (select id from link inner join person P1 on child = person.id where person.name = 'John') B on P2.id = B.id where P2.name <> 'John' |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Just for sisters... select P2.name, P2.sex from person P2 inner join link on P2.id = link.parent inner join (select id from link inner join person P1 on child = person.id where person.name = 'John') B on P2.id = B.id where P2.name <> 'John' and P2.sex='Female' |
#6
| |||
| |||
|
|
Just for sisters... select P2.name, P2.sex from person P2 inner join link on P2.id = link.parent inner join (select id from link inner join person P1 on child = person.id where person.name = 'John') B on P2.id = B.id where P2.name <> 'John' and P2.sex='Female' When I try to run the above query in Access, I get the following message: "Syntax error (missing operator) in query expression P2.id = link.parent inner join .... P2.id = B.id" What am I doing wrong? Below is the query for john's sisters that executes ok. SELECT P2.name FROM ((person INNER JOIN link ON person.id = link.child) INNER JOIN link AS link2 ON link.parent = link2.parent) INNER JOIN person AS P2 ON link2.child = P2.id WHERE (((P2.name)<>"John") AND ((person.name)="John") AND ((P2.sex)="Female")); Forgot to mention that the query I provided is SQL Server compliant .I |
#7
| |||
| |||
|
|
Just for sisters... select P2.name, P2.sex from person P2 inner join link on P2.id = link.parent inner join (select id from link inner join person P1 on child = person.id where person.name = 'John') B on P2.id = B.id where P2.name <> 'John' and P2.sex='Female' Forgot to mention that the query I provided is SQL Server compliant .I do not think Access does JOIN on selects. You may need to package the inner select in a view then do a JOIN on that view... |
#8
| |||
| |||
|
|
Just for sisters... select P2.name, P2.sex from person P2 inner join link on P2.id = link.parent inner join (select id from link inner join person P1 on child = person.id where person.name = 'John') B on P2.id = B.id where P2.name <> 'John' and P2.sex='Female' Forgot to mention that the query I provided is SQL Server compliant .I do not think Access does JOIN on selects. You may need to package the inner select in a view then do a JOIN on that view... I packaged the inner expression in query Q_B as follows: SELECT person.id FROM link INNER JOIN person ON link.child = person.id WHERE (((person.name)='John')); Updated original query as follows: select P2.name from person P2 inner join link on P2.id = link.parent inner join Q_B B on P2.id = B.id where P2.name <> 'John' and P2.sex='Female' I realize I made a mistake... |
#9
| |||
| |||
|
|
create view as Q_B SELECT DISTINCT person.id FROM link INNER JOIN person ON link.child = person.id WHERE (((person.name)='John')) --> This view gets the id of the parent for a specific sibling... |
|
select P2.name from person P2 inner join link on Q_B B on P2.parent = B.id where P2.name <> 'John' --> This view gets all sibling's for a specific parent id then |
#10
| |||
| |||
|
|
This view gets the id of the parent for a specific sibling... create view as Q_B SELECT DISTINCT person.id FROM link INNER JOIN person ON link.child = person.id WHERE (((person.name)='John')) |
|
This view gets all sibling's for a specific parent id then restricts name ... select P2.name from person P2 inner join link on Q_B B on P2.parent = B.id where P2.name <> 'John' |
![]() |
| Thread Tools | |
| Display Modes | |
| |