1

there are 4 tables:A,B,C,D
there is an id:4(input)
the query should print the number of times the id is present in the tables

EX:

in table A id:4 occurs 5 times
in table B id:4 occurs 7 times
in table C id:4 occurs 3 times
in table D id:4 occurs 1 times

output:

Table name       No of occurence

A                   5
B                   7
C                   3
D                   1

3 Answers 3

2

you can try something like that:

select 'A', count(*) from a where id = 4
union all
select 'B', count(*) from b where id = 4
union all
select 'C', count(*) from c where id = 4
union all
select 'D', count(*) from d where id = 4
Sign up to request clarification or add additional context in comments.

Comments

0
select id as Name,count(id) as occurence from tableA where id = 4 group by id
union all
select id as Name,count(id) as occurence from tableB where id = 4 group by id
union all
select id as Name,count(id) as occurence from tableC where id = 4 group by id
union all
select id as Name,count(id) as occurence from tableD where id = 4 group by id

Comments

0

Do the union all

select 'A' as Name, count(*) as occurence from tablea where id = ?
union all
select 'B' as Name, count(*) as occurence from tableb where id = ?
union all
select 'C' as Name, count(*) as occurence from tablec where id = ?
union all
select 'D' as Name, count(*) as occurence from tabled where id = ?

1 Comment

you can quote the names if you want spaces: select count(*) as 'No of occurance'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.