Hi Guys!
I am using the following SQL query, which works perfectly.
SELECT UNIX_TIMESTAMP( dt_auctions.end_date ) - UNIX_TIMESTAMP( ) AS time_left, dt_auctions.paid_auction, dt_auctions.high_bid, dt_domains. * , dt_currencies.symbol AS currency_symbol
FROM dt_domains
INNER JOIN dt_currencies ON dt_currencies.code = dt_domains.currency
LEFT OUTER JOIN dt_auctions ON dt_auctions.domain_id = dt_domains.id
WHERE end_date > now( )
AND active = '1'
AND dt_auctions.status = 'active'
ORDER BY end_date ASC
LIMIT 0 , 30
However, I also need to get the total number of bids for each auction. To do this I am trying to do a left outer join on the “bids” table. The problem is there may not always be bids for each auction (so this table could be empty).
Here’s the new SQL query I am trying. It only returns 1 row when in fact it should return 2 rows as there are 2 active auctions. I hope this makes sense.
SELECT UNIX_TIMESTAMP( dt_auctions.end_date ) - UNIX_TIMESTAMP( ) AS time_left, COUNT( dt_bids.id ) AS bids, dt_auctions.paid_auction, dt_auctions.high_bid, dt_domains . * , dt_currencies.symbol AS currency_symbol
FROM dt_domains
INNER JOIN dt_currencies ON dt_currencies.code = dt_domains.currency
LEFT OUTER JOIN dt_auctions ON dt_auctions.domain_id = dt_domains.id
LEFT OUTER JOIN dt_bids ON dt_bids.auction_id = dt_auctions.id
WHERE end_date > now( )
AND active = '1'
AND dt_auctions.status = 'active'
ORDER BY end_date ASC
Please help