0

Not sure if this is possible in a single query but looking to do this directly in SequelPro.

I have a table containing cars, and if they are sold or live.

I also have another table which is called data_store and contains some information about those cars. However, not all of the cars have data in this table.

To get the cars that are live is currently:

SELECT * from cars where `sale_status` = 'live'

I now need it to be like:

SELECT * from cars where `sale_status` = 'live' AND THERE IS A ROW IN THE DATA_STORE TABLE FOR THIS CARS REGISTRATION NUMBER.

There is a registration number field in each of the tables.

Thanks, still getting my head around joins.

Lovelock
  • 7,689
  • 19
  • 86
  • 186
  • looking up some information about join and left join will be very helpful for you. http://www.w3schools.com/sql/sql_join.asp have a read! – user3012759 Feb 18 '15 at 17:32

1 Answers1

2

You want to do a simple join :

select *
from cars
join data_store on cars.registration_number = data_store.registration_number

change registration_number with whatever is the link with cars in data_store.

This will return only cars containing a row in data_store.

Jean-François Savard
  • 20,626
  • 7
  • 49
  • 76