Click here to Skip to main content
15,861,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
select Item_Code from Product_Item_Dtls where Cate_Id=2 and ((SubCate_Id='2' and SubCate_Value='HNBR') and (SubCate_Id='1' and SubCate_Value='10') and (SubCate_Id='4' and SubCate_Value='1.74') and (SubCate_Id='3' and SubCate_Value='10.10') and (SubCate_Id='5' and SubCate_Value='Black'));


getting no data while running the above query.

actually I want run above query for searching single value with multiple criteria but don't want to use "IN" because want
SubCate_Id
with
SubCate_Value
both are depend on each other

please help I m stuck here...

What I have tried:

Running same query as i mentioned ...

Dont want to use IN
Posted
Updated 18-Jul-20 3:07am

1 solution

AND requires the expression on both sides to be TRUE in order for it to return true:
X > 5 AND Xx < 10
For example.
What you are asking for is
X = 5 AND X = 10
And since a single value cannot equal two different values at the same time, you will always get FALSE from that, regardless of the value of X.

Probably, you want OR, not AND - it returns TRUE if either or both of teh conditiosn it TRUE, and only returns FALSE if both are FALSE:
X = 5 OR X = 10
 
Share this answer
 
v2
Comments
hareshdgr8 18-Jul-20 9:11am    
sir i have one table that contains one itemcode and that item code have different parameter I want to fetch item code using multiple parameter like as below

Code Cate_Id SubCate_Id SubCate_Value
ORG62 2 2 HNBR
ORG62 2 1 10
ORG62 2 4 1.74
ORG62 2 3 10.1
ORG62 2 5 Black

ORG63 1 2 HNBR
ORG63 1 1 10
ORG63 1 4 1.74
ORG63 1 3 10.1
ORG63 1 5 Black



sir, I want ORG62 code using the above query what I can do sir...

sir MY CATE 2 and 1 but can upload as per database design
OriginalGriff 18-Jul-20 10:03am    
At a guess, you'll want to use GROUP BY to select your ID, then a HAVING clause with OR conditions.

But it's not all that clear exactly what you expect.
hareshdgr8 20-Jul-20 1:18am    
sir i want all combination and want one code ORG62 that's why using AND not using OR in query

I have combination value

(SubCate_Id='2' and SubCate_Value='HNBR') and (SubCate_Id='1' and SubCate_Value='10') and (SubCate_Id='4' and SubCate_Value='1.74') and (SubCate_Id='3' and SubCate_Value='10.10') and (SubCate_Id='5' and SubCate_Value='Black') with this combination all have one Item Code i.e. ORG62

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900