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
 SQL Server Development (2000)
 OR problem

Author  Topic 

Ian96
Starting Member

3 Posts

Posted - 2009-12-17 : 05:49:23
I have this query,

SELECT * FROM product, product_categories
WHERE (product_categories.categoryId IN (565) AND product.productId = product_categories.productId) OR (product.name LIKE '%gold%' OR product.description LIKE '%gold%')

Its for a product search. Ive done a query to get the category id from the search criteria. The above query then shud get results that have either the category 565 or the likes.

At the moment their is nothing in product_categories but their is a product that contains gold in its description. Yet it brings back no results.

Its a problem because I need a page nav and Im gonna have to do it myself if I have to do two queries.

Thanks

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-17 : 07:21:44
SELECT p.* FROM product as p left outer join product_categories as pc
on p.productId = pc.productId
and pc.categoryId IN (565) OR (p.name LIKE '%gold%' OR p.description LIKE '%gold%')


Madhivanan

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

Ian96
Starting Member

3 Posts

Posted - 2009-12-17 : 07:37:17
Well its getting somewhere because Its bringing back results. Problem is its bringing back all the products.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-17 : 07:52:17
SELECT p.* FROM product as p left outer join product_categories as pc
on p.productId = pc.productId
on pc.categoryId IN (565)
where (p.name LIKE '%gold%' OR p.description LIKE '%gold%')


Madhivanan

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

Ian96
Starting Member

3 Posts

Posted - 2009-12-17 : 08:22:16
did not work initially but with your code just moved one bit and its sorted. Below is the code.


SELECT p.* FROM product as p left outer join product_categories as pc
on p.productId = pc.productId
where (p.name LIKE '%gold%' OR p.description LIKE '%gold%')
or pc.categoryId IN (565)

Thanks and merry christmas madhivanan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-17 : 08:28:16
quote:
Originally posted by Ian96

did not work initially but with your code just moved one bit and its sorted. Below is the code.


SELECT p.* FROM product as p left outer join product_categories as pc
on p.productId = pc.productId
where (p.name LIKE '%gold%' OR p.description LIKE '%gold%')
or pc.categoryId IN (565)

Thanks and merry christmas madhivanan


Thansk and You are welcome

Madhivanan

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

- Advertisement -