hariprasadraja
10/23/2019 - 5:51 AM

sql select combine two sql statmenets using UNION


-- Union combines two sql statements into one response
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions]
UNION [DISTINCT]
SELECT expression1, expression2, ... expression_n
FROM tables
[WHERE conditions];
SELECT * FROM (
  SELECT CONCAT(name, '(', SUBSTRING(occupation, 1, 1), ')') AS name
  FROM occupations
  ORDER BY name ASC
) temp1
UNION
SELECT * FROM (
  SELECT concat('There are a total of ', count(*), ' ', LOWER(occupation), 's.')
  FROM occupations
  GROUP BY occupation
  ORDER BY COUNT(*)
) temp2
ORDER BY name