B
B
bycter2015-10-05 19:31:01
MySQL
bycter, 2015-10-05 19:31:01

How to create a MySQL query to select from two tables?

There are two tables of the form: date1, temp1 and date2, temp2.
Both include date and temperature. I need to find the minimum temperature for the specified period in the first table, find the temperature value in the second table (by the date that corresponds to the minimum temperature) and display all this in a table of the form: date1, temp1, temp2.
Can you please tell me what such a request might look like?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2015-10-05
@melkij

select date1, temp1, temp2 from table2 join (
select date1, temp1 from table1 where date1 >= :period_from and date1 <= :period_till order by temp1 desc limit 1 -- по старому обыкновению, мог перепутать asc/desc
) mintable1 ON date1 = date2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question