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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select a column that may have no data ?

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.manufacturers
from products p, products_description pd, manufacters
where (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_id
AND p.manufacturers_id = m.manufacturers_id

Can anyone help

Many thanks
Dinalli

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
Go to Top of Page

Dinalli
Starting Member

2 Posts

Posted - 2006-12-31 : 08:08:24
many thanks that did the trick.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-01 : 03:30:43
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -