0

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.

3
  • What database are you using? The answer could change based on the platform. :) Commented Aug 29, 2012 at 16:12
  • Is there only one row in the result of your query? And what is the datatype of table1.abc? Commented Aug 29, 2012 at 16:14
  • @lc yes there is only 1 row per set of col1,col2 Commented Aug 29, 2012 at 17:51

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Could you comment on efficiency of this over the other? Are there any plus points?
1

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 = ?)

1 Comment

this would return three rows..but i need only 1 row in result set but 3 columns in that row

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.