I have a table in sql where, I want to retrieve data based on two columns by passing a two list of values. for example:- lets consider a table with table name "employee"
-----------------------------
| project_id | resource_id |
-----------------------------
| 7 | 46 |
-----------------------------
| 7 | 87 |
-----------------------------
| 5 | 87 |
------------------------------
I would like to retrieve data based on exact match of values in both the columns just like
"select * from employee where project_id = 7 and resource_id = 46;"
then it returns the first row. if the query would be like this
"select * from employee where project_id in (7,5) and resource_id in
(46,87);"
it will return all the three rows instead of first and third row. I can understand that the 'sql' engine executes the query by all the combination of the values given. but, I need the query to process the data for the above values, so as to return the first and third row. Is there any solutions? Thanks in advance.
If your dbms supports row types etc:
select *
from employee
where (project_id, resource_id) in ((7, 46), (5, 87))
ISO/ANSI SQL compliance:
The following features outside Core SQL-2003 are used:
F641, "Row and table constructors"
T051, "Row types"
F561, "Full value expressions"
(According to http://developer.mimer.se/validator/parser200x/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With