I have these simple SQL statements:
SELECT COUNT(ID) AS Expr1
FROM Table1
UNION
SELECT COUNT(ID) AS Expr2
FROM Table1 AS Table1_1
WHERE (UPDATED > CREATED)
UNION
SELECT COUNT(DISTINCT DATEPART(year, UPDATED)) AS Expr3
FROM Table1 AS Table1_2
I want to show results as:
Expr1 Expr2 Expr3
----- ----- -----
5 3 2
How to do that ? I understand that UNION is more reliable and faster than using OR in WHERE clause.
You cannot do this with
UNION– that will give you a union of rows – not columns.For your requirement, try something like this:
That will give you one row with three columns, containing the values you’re looking for.