Hi all,
I'll try and explain this the best way I can, but, feel free to ask if I'm not clear enough.
I have two tables and I want to return all of the data in table 1 and at the same time check if there's more data that is in table 2 linked to the rows via foreign key, so basically I'd have all the data in table 1 and a true or false depending on whether or not a foreign key on table 2 matches a primary key on table 1.
I'm not sure if this can be done with a single statement, but here is an example of the tables.
so, in theory I'm trying to get it to return...
Thanks for your time.
I'll try and explain this the best way I can, but, feel free to ask if I'm not clear enough.
I have two tables and I want to return all of the data in table 1 and at the same time check if there's more data that is in table 2 linked to the rows via foreign key, so basically I'd have all the data in table 1 and a true or false depending on whether or not a foreign key on table 2 matches a primary key on table 1.
I'm not sure if this can be done with a single statement, but here is an example of the tables.
Code:
Table1
RowID(pk) FirstName LastName DateOfBirth Email
--------------------------------------------------------------------------------------------
1 David Stonewall 01/03/1954 david@sql-tutorial.com
2 John Smith 12/12/1969 john.smith@john-here.com
3 Susan Grant 03/03/1970 susan.grant@sql-tutorial.com
4 Stephen Grant 03/03/1974 sgrant@sgrantemail.com
5 Paul O'Neil 09/17/1982 paul.oneil@pauls-email.com
Code:
Table2
RowID InfoID(fk) BookedDate AmountOfWeeks
-----------------------------------------------------
1 2 11/01/2009 2
2 5 02/03/2009 1
so, in theory I'm trying to get it to return...
Code:
RowID(pk) FirstName LastName DateOfBirth Email MoreData
----------------------------------------------------------------------------------------------------------
1 David Stonewall 01/03/1954 david@sql-tutorial.com false
2 John Smith 12/12/1969 john.smith@john-here.com true
3 Susan Grant 03/03/1970 susan.grant@sql-tutorial.com false
4 Stephen Grant 03/03/1974 sgrant@sgrantemail.com false
5 Paul O'Neil 09/17/1982 paul.oneil@pauls-email.com true
Thanks for your time.