Skip to content
Advertisement

SQL Get certain value form two tables and make result set multiple rows

I have two tables:

TABLE 1
name age year
John 20 2001
Amy 21 2002

Table 2 
name age year
John 20 2001
Kal 21   2000


SELECT * FROM Table1 AND Table2 WHERE name = 'john';

I tried using the statement above but it would not work.

I need the statement to return all the tables that have the word john in it.

Advertisement

Answer

You want union all:

select name, age, year
from table1
where name = 'John'
union all
select name, age, year
from table2
where name = 'John'
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement