Home > Mobile >  Return also empty matches from SQL query
Return also empty matches from SQL query

Time:01-04

I use this SQL query to get data:

SELECT * 
FROM common.ACTIVE_PAIRS ap 
INNER JOIN exchanges ON exchanges.exchange_id = ap.exchange_id 
ORDER BY :sort 
LIMIT :limit 
OFFSET :offset

The issue is that sometimes ap.exchange_id can be empty and I don't have a row. Do you know how I can return the result with empty ap.exchange_id?

CodePudding user response:

This is exactly what outer (or left) joins are for:

SELECT * 
FROM common.ACTIVE_PAIRS ap 
LEFT JOIN exchanges ON exchanges.exchange_id = ap.exchange_id -- Note the left join
ORDER BY :sort 
LIMIT :limit 
OFFSET :offset
  •  Tags:  
  • Related