praveen
praveen

Reputation: 27

how to display serial number in sql

How to display the serial number for the below

select count(*) toatl_count, "employee is Invalid" error from emp
union
select count(*) total_count, "comapny name is incorrect" error from company;

result will be

total_count error
10          employee is Invalid
55          comapny name is incorrect

but I need output as below

serial number total_count error
     1         10          employee is Invalid
     2        55          comapny name is incorrect

Upvotes: -5

Views: 77

Answers (1)

BigBang
BigBang

Reputation: 1

Try this:

SELECT 
  ROW_NUMBER() OVER() AS serial_no,
  total_count, 
  error
FROM (
  SELECT count(*) total_count, '"employee is Invalid"' error FROM emp
  UNION
  SELECT count(*) total_count, '"company name is incorrect"' error FROM company
) subquery
ORDER BY serial_no;

Upvotes: 0

Related Questions