Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple SQL tables added together without a JOIN

Tags:

sql

I have two tables:

  FirstField | SecondField | ThirdField

  FirstValue   SecondValue   ThirdValues

----------------------------------------------
 FirstField  | SecondField | ThirdField

 OtherValue1   OtherValue2   OtherValue3

What I need it to add those two tables together into one SQL query. They can not be joined as I don't have anything to join them on and that's not what I want. I want my new table to look like:

 FirstField | SecondField | ThirdField

 FirstValue   SecondValue   ThirdValues

 OtherValue1   OtherValue2   OtherValue3

This may be very simple but I am new to SQL and have been unable to find any help elsewhere.

like image 866
mo alaz Avatar asked Oct 04 '22 08:10

mo alaz


1 Answers

Try UNION ALL:

SELECT FirstField ,SecondField ,ThirdField 
FROM   Table1
UNION  ALL
SELECT FirstField ,SecondField ,ThirdField 
FROM   Table2

If you want to remove duplicate rows use UNION instead.

SELECT FirstField ,SecondField ,ThirdField 
  FROM Table1
 UNION
SELECT FirstField ,SecondField ,ThirdField 
  FROM Table2
like image 199
Himanshu Jansari Avatar answered Oct 12 '22 17:10

Himanshu Jansari