mysql - SQL query, two tables, multiple items -
i wish retrieve data 2 tables twist, need multiple values (prices different dates) second table. following works fine, not of sql jockey , have sneaking suspicion there must better way joining second table twice. there?
select a.date, a.symbol, a.value, b.close, c.close potential left join stock_daily b on a.symbol = b.symbol left join stock_daily c on a.symbol = c.symbol a.date = "2015-08-05" , b.date = "2015-08-05" , c.date = "2015-08-04" order value desc limit 20;
thanks in advance!
it fine way you're doing it, expand bit more on comment, there potential issue query. since doing left join
conditional logic in where
clause joined table, transforming left join
inner join
.
should there dates missing right-hand table not satisfy inner join
, give incorrect results.
i recommend changing query following avoid this:
select a.date, a.symbol, a.value, b.close, c.close potential left join stock_daily b on a.symbol = b.symbol , b.date = "2015-08-05" left join stock_daily c on a.symbol = c.symbol , c.date = "2015-08-04" a.date = "2015-08-05" order value desc limit 20;
Comments
Post a Comment