简体   繁体   中英

MySQL left join match based on distinct values

I'm looking to join two tables based on dates. The date value in one of the tables can occur multiple times but I need a match based on a unique instance of the date. Here is what I have that does not work:

select idt.Incident_DateCopy, wt.weather_main
 from incidentdatatwo as idt left join weather as wt on 
     (select distinct(Incident_DateCopy) from incidentdata) as idate = wt.dt_iso

...

try this

if not work so please send you table schema

SELECT idt.Incident_DateCopy, wt.weather_main , 
(SELECT DISTINCT(Incident_DateCopy) FROM incidentdata) AS idate 
 FROM incidentdatatwo AS idt LEFT JOIN weather AS wt ON
HAVING idate = wt.dt_iso

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM