How to group by two rows in a column

Left join location table on data to get all locations regardless if there is match in data table, group by location id and location, and I assume you want to get the 1st name (min()):

select, l.location, min( as name
from location l
left join data d on l.location=d.location
group by, l.location

Alternatively, if you want to get for a data item if it has offshore and onshore record:

select, l.location,
from location l
join data d
left join data d2 on l.location=d2.location

Browse More Popular Posts

Leave a Comment