Reputation: 45
SELECT JIVE_USER_ID,
EMAIL_ID,
USER_ID
FROM VIK_USER WHERE EMAIL_ID='[email protected]';
JIVE_USER_ID EMAIL_ID USER_ID
11222 [email protected] User
SELECT VIK_USER_PROFILE.FIRST_NAME,
VIK_USER_PROFILE.LAST_NAME,
VIK_USER.EMAIL_ID
FROM VIK_USER,VIK_USER_PROFILE
WHERE VIK_USER_PROFILE.USER_ID=VIK_USER.USER_ID;
FIRST_NAME LAST_NAME EMAIL_ID
Ray User [email protected]
I want to get the result using a single block statement.How can I join these two select statements into one.
Thank You.
Upvotes: 3
Views: 1121
Reputation: 499
The answer above joins the tables and filters based on where or and clause. This may be inefficient for big tables. Instead filter the table for particular id and then join.
Upvotes: 0
Reputation: 3164
select VIK_USER.JIVE_USER_ID,
VIK_USER.EMAIL_ID,
VIK_USER.USER_ID,
VIK_USER_PROFILE.FIRST_NAME,
VIK_USER_PROFILE.LAST_NAME,
VIK_USER.EMAIL_ID
from VIK_USER, VIK_USER_PROFILE
where VIK_USER_PROFILE.USER_ID=VIK_USER.USER_ID
and VIK_USER.EMAIL_ID='[email protected]'
To elaborate, VIK_USER and VIK_USER_PROFILE are in an INNER JOIN (the comma is just a shortcut).
The join condition is VIK_USER_PROFILE.USER_ID=VIK_USER.USER_ID
. JOINs have join conditions, usually on columns which share the same values across two tables.
Alternatively, the exact same query can be written as such:
select *
from VIK_USER
inner join VIK_USER_PROFILE on VIK_USER_PROFILE.USER_ID=VIK_USER.USER_ID
where VIK_USER.EMAIL_ID='[email protected]';
Upvotes: 3