Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
12-14-2012, 12:05 PM #1
- Join Date
- Sep 2012
- Thanked 0 Times in 0 Posts
Join where there is sometimes no value?
Hello, I am after some help please. I have two tables, which I wish to query to output all the records in table_a.
- In table_a I have a field named 'thecategoryid'
- In table_b I have a field named 'categoryid'
But my problem is in table_a 'thecategoryid' field in each row can sometimes contain a value and sometimes not, so I can't join like so
table_a.thecategoryid = table_b.catgoryid
So how can I output all records in table_a with a join on table_b but with it not mattering if there is or there is not a value on the row 'thecategoryid'
Is this possible?
Last edited by Oatley; 12-14-2012 at 02:34 PM.
12-14-2012, 01:56 PM #2
- Join Date
- Sep 2002
- Saskatoon, Saskatchewan
- Thanked 2,650 Times in 2,619 Posts
Sure you can. Just use a LEFT JOIN to fetch all records from the primary table (governed by the where clause of course), and any matching records from the child table.
Users who have thanked Fou-Lu for this post: