Query sql to 2 related tables

1

I'm trying to list results from two related tables, but I'm not capable.

These are the simplified tables:

table1

id | fecha

table2

id | horario

I'm trying to filter the results by date range and show the time column of the other table.

My code editor shows me in purple the text tabla1.id = tabla2.id so I guess that part will not be well formulated.

"SELECT * FROM tabla1 JOIN tabla2 ON tabla1.id = tabla2.id WHERE fecha BETWEEN '$fechahoy' AND '$fechahoy' "

Thank you very much for your time and help

Regards,

    
asked by Xavier Villafaina 20.06.2018 в 23:39
source

1 answer

0

Xavier hello, as I understand you want to join two tables and show the data of Table 1 and some data of Table 2, filtering by a range of dates.

I think this is what you want to see:

" SELECT t1.*, t2.horario
FROM tabla1 AS t1 JOIN tabla2 AS t2 ON t1.id = t2.id 
WHERE t1.fecha BETWEEN '$fechahoy' AND '$fechahoy' "

Keep in mind that the date filter with the BETWEEN clause allows you to filter by date1 and date2, in your example the date variable seems to be the same (today), if that is correct you can place that filter as follows:

... WHERE t1.fecha = '$fechahoy' "

I hope I understood and helped you. Happy day ..

    
answered by 23.06.2018 в 07:23