Reputation:
I want to join 2 tables but they both have email and password and I want both of the tables to be joined as a new row and not next to each other
So instead of:
c.email | c.password | u.email | u.password
[email protected] companypass [email protected] userpass
I want it to be like
email | password
[email protected] companypass
[email protected] userpass
This is the current query I have which leads to the first example:
SELECT
u.email, u.password, c.email, c.password
FROM
korisnici_tbl AS u, companies_tbl AS c
Upvotes: 0
Views: 12635
Reputation: 726509
If you'd like to keep rows from both tables, you do not need a join, you need a UNION
:
SELECT u.email, u.password FROM korisnici_tbl AS u
UNION ALL
SELECT c.email, c.password FROM companies_tbl AS c
The ALL
option will keep duplicates, if any are found in both tables. If you want duplicates removed, drop ALL
from the UNION
.
Upvotes: 1
Reputation: 191729
If you want them to be in different rows, you can use a UNION
(or UNION ALL
, which allows duplicate rows)
SELECT email, password FROM companies_tbl
UNION ALL SELECT email, password FROM korisnici_tbl
Upvotes: 3
Reputation: 62831
One option is to use a UNION
:
SELECT email, password
FROM korisnici_tbl
UNION
SELECT email, password
FROM companies_tbl
If you want potential duplicate rows, use UNION ALL
instead.
Upvotes: 1