Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Dinalli
Starting Member
2 Posts |
Posted - 2006-12-30 : 11:27:51
|
Hi i wonder if i can get some help.Im trying to get my head around a query i am writting.I need to get a value back from a column that may or may not have a value in it.The SQL i currently have is this and it works fine, but i need to add another table to he query which is simply a product_id and product_barcode and need to return the barcode if one exists.When i add this to my query it only returns products which have a barcode. But not evey product has a barcode so i need them all returned.select DISTINCT p.products_id, p.products_model, pd.products_name, products_quantity, p.products_price , m.manufacturersfrom products p, products_description pd, manufacterswhere (pd.products_name LIKE '%white%'OR p.manufacturers_id IN (SELECT manufacturers_id from manufacturers where manufacturers_name LIKE '%white%'AND p.products_id = pd.products_idAND p.manufacturers_id = m.manufacturers_idCan anyone helpMany thanksDinalli |
|
Kristen
Test
22859 Posts |
Posted - 2006-12-30 : 11:58:25
|
You need to use a LEFT OUTER JOIN to your Barcode Table, and that will return NULL values for any row missing from the barcode table....from products p LEFT OUTER JOIN MyBacodes AS B ON B.products_id = p.products_id... Kristen |
 |
|
Dinalli
Starting Member
2 Posts |
Posted - 2006-12-31 : 08:08:24
|
many thanks that did the trick. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|