there are two tables:
TABLE cars
id | date
----------
1 | 2012-01-04
2 | 2012-01-04
3 | 2012-01-05
TABLE versions
id_car | year | author
-------------------------
1 | 2005 | John
1 | 2001 | Carl
2 | 2003 | Carl
2 | 2001 | John
3 | 2004 | Carl
3 | 2003 | John
I need to get all the information about cars with yesterday’s date (2012-01-04) and information about their latest version if author is Carl.
So in this example I need to get:
2 | 2012-01-04 | 2003 | Carl
You want an
inner join:In this query, you’re saying, “Grab me everything from
carswhere the date is2012-01-04and then find everything inversionswhere theid_carcolumn is equal to myidcolumn incars. Oh, and only give me anything fromversionswhere the author isCarl, but only where the year of the car is equal to the greatest year of the car that’s available.”