Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select everything from two table based on the same ID

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.

like image 452
sefirosu Avatar asked Feb 03 '26 19:02

sefirosu


1 Answers

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>
like image 144
podiluska Avatar answered Feb 05 '26 13:02

podiluska



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!