Rachit Agrawal
Rachit Agrawal

Reputation: 735

Alternative of executing same sql query again with different parameters

I need to do the following :

select table1.abc from table1 where col1 = ? and col2 = ?

The problem here is i need to get data from this table for 3 sets of (col1, col2). I don't want to execute the same query 3 for different parameters.

Also i want to have the result set of the executed query containing 3 columns of data (1 for each set of col1,col2).

Let me know if any further details are reqd.

Upvotes: 0

Views: 758

Answers (2)

sqlhdv
sqlhdv

Reputation: 254

You can use OR clause with 3 sets having different parameter set

select table1.abc from table1 where (col1 = ? and col2 = ?)
OR (col1 = ? and col2 = ?) OR (col1 = ? and col2 = ?)

Upvotes: 1

lc.
lc.

Reputation: 116458

You can just use subselects if there's only one result for your query:

select (select table1.abc from table1 where col1 = ? and col2 = ?),
    (select table1.abc from table1 where col1 = ? and col2 = ?),
    (select table1.abc from table1 where col1 = ? and col2 = ?)
from table1
limit 1

Upvotes: 1

Related Questions