Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top