Reputation: 2658
I have two tables:
base_profile: id, first_name, last_name, address
flight_profile: id, flight_no, destination
How do i select all fields from these two tables based on the same id? My assumption would be :
SELECT *
FROM base_profile, flight_profile WHEN base_profile.id == flight_profile.id
WHERE id, first_name,last_name,address,flight_no,destination
I know this is not right. Can anyone help me to correct it please? Thanks.
Upvotes: 3
Views: 14404
Reputation: 41
How to select inner join where ID = 1 from (sample) above code
SELECT base_profile.id,
base_profile.first_name,
base_profile.last_name,
base_profile.address,
flight_profile.flight_no,
flight_profile.destination
FROM base_profile
INNER JOIN flight_profile
ON base_profile.id = flight_profile.id
WHERE base_profile.id = 1
Upvotes: 2
Reputation: 51514
Using an inner join
SELECT base_profile.id, base_profile.first_name, base_profile.last_name, base_profile.address,
flight_profile.flight_no,flight_profile.destination
FROM base_profile INNER JOIN flight_profile
ON base_profile.id = flight_profile.id
or more generally
SELECT <fields you want to return>
FROM <tables linked with joins>
Upvotes: 7