Sahil Jasuja-sj
Sahil Jasuja-sj

Reputation: 1

Code to combine two sql queries

I want to join these two queries to get the result in one query. How do I do that?

SELECT Serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('1','2');
SELECT serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('3','4') AND [serial_no]%2=0

Upvotes: 0

Views: 78

Answers (3)

roman
roman

Reputation: 117345

select
    t.serial_no, t.booth_no
from table as t
where
    t.booth_no in ('1','2') or
    t.booth_no in ('3','4') and t.[serial_no] % 2 = 0

Upvotes: 1

Adriaan Stander
Adriaan Stander

Reputation: 166356

Why do you need to seperate the queries?

Try using something like

SELECT  Serial_no,
        BOOTH_NO 
FROM    table 
WHERE   BOOTH_NO IN ('1','2')
OR      (BOOTH_NO IN ('3','4') AND [serial_no]%2=0)

Upvotes: 3

kba
kba

Reputation: 19466

You can use the UNION keyword.

(SELECT Serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('1','2'))
UNION
(SELECT serial_no,BOOTH_NO FROM table WHERE BOOTH_NO IN ('3','4') AND [serial_no]%2=0)

Upvotes: 1

Related Questions