AlexPonnath
asked on
Simplify a SQL query
I am currently using 2 Queries to get to the value i am looking for and am wondering if i could do this in one.
My table has 2 Col's of intrest lets called them ColA and ColB
ColA ColB
==============
10001 50
10008 50
10014 50
10002 51
10009 51
10015 51
10003 52
10009 52
and so on, i have the value of ColA lets say 10002 and i need to find the largest value
in my table for ColA where ColB = the same as for the row of 10002 which is 51 in the
sample case.
Right now i query for Colb based on 10002 and then in a second query i select max of
colA where colB = the value i got infirst query.
Any ideas to do this in one query would be great
My table has 2 Col's of intrest lets called them ColA and ColB
ColA ColB
==============
10001 50
10008 50
10014 50
10002 51
10009 51
10015 51
10003 52
10009 52
and so on, i have the value of ColA lets say 10002 and i need to find the largest value
in my table for ColA where ColB = the same as for the row of 10002 which is 51 in the
sample case.
Right now i query for Colb based on 10002 and then in a second query i select max of
colA where colB = the value i got infirst query.
Any ideas to do this in one query would be great
Please show us the query you are using now.
Is this what you're doing now:
select ColA,ColB from myTable where ColB=(select ColB from myTable where ColA=1002)?
select ColA,ColB from myTable where ColB=(select ColB from myTable where ColA=1002)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.