15,936,903 members
See more:
Hi All,

I am using sql server 2012. Can anybody please guide how I can combine the following 2 commands into one.

SQL
```Select distinct PROJN from PROJ
JOIN [USER] ON PROJ.PROJWD=[USER].USERT WHERE ([USER].USERID=@USER)
;

Select distinct PROJN from PROJ
WHERE PROJ.PROJWD IN (SELECT DEPTN FROM DEPT WHERE DEPTH=@USER or deptd=@USER)```

I require the resultant datatable to have distinct combine result of both queries.
For coding I am using vb in asp.net.

Posted
PIEBALDconsult 23-Nov-14 0:45am
UNION ?
atul sharma 5126 23-Nov-14 1:24am
Thanks! If this is put in solution I will accept the same
How do you want the results combined?
Do you want the rows that satisfies both queries, or the rows that satisfies either query

## Solution 3

SQL
```You can use either union or union all to combine the two queries.

Select distinct PROJN from PROJ
JOIN [USER] ON PROJ.PROJWD=[USER].USERT WHERE ([USER].USERID=@USER)

union/Union all

Select distinct PROJN from PROJ
WHERE PROJ.PROJWD IN (SELECT DEPTN FROM DEPT WHERE DEPTH=@USER or deptd=@USER)```

## Solution 2

Use of UNION has solved the matter as suggested by PIEBALDconsult.

Thanks

## Solution 1

You can try this also
SQL
```Select distinct PROJN from PROJ
JOIN [USER] ON PROJ.PROJWD=[USER].USERT WHERE ([USER].USERID=@USER)
or PROJ.PROJWD IN (SELECT DEPTN FROM DEPT WHERE DEPTH=@USER or deptd=@USER)```