dimanche 28 juin 2015

mySQL innerjoin with where condition does not work

i'm trying to get a result of an mysql query for the last hours but did not get it. i hope you can help me. i have 2 sql tables. 1st is called 'drives' and is quite big with more than 200000 rows and 30 colums and a structure like: plate | time from | time to ab222 | 2015.05.12 08:00 | 2015.05.13 11:37 cv481 | 2015.05.14 12:08 | 2015.05.14 14:11

the second is called 'fuel' and is much shorter with about 5000 rows but also 22 colums. the structure of that is like: plate | time | amount | price ab222 | 2015.05.13 09:22 | 2.3 | 32.22 cv481 | 2015.05.14 13:59 | 12.2 | 17.7

what I'm going to do is to show for each row in 'fuel' table the right 'drive'. that means the time of the 'fuel' table has to be between the 'from time' and the 'to time' of the 'drives' table and the plate must be the same. the result should show the columns of both tables (so about 52 colums and 5000 rows because for each row in 'fuel' table must be one fitting drive in 'drive' table).

I'm not used to work with mysql so I googled a lot and tryed a lot. the following i made seems to be close to what I need:

INNER JOIN fuel.* ON
drives.plate = fuel.plate
WHERE fuel.time Between
drives.timefrom AND
drives.timeto

but it didnt work.

Aucun commentaire:

Enregistrer un commentaire