[thelist] 2 columns infos in one query ?

Damien COLA damiencola at wanadoo.fr
Mon Dec 29 19:04:15 CST 2003


Hello all,

This one is for Rudy's followers and other sql experts, not really web
design related..

I'd like to display, by days, how many ads were added by how many
sellers.

I have this table with those fields :
adID (primary key, auto increment)
added_date (in Y-m-d format)
sellerID (pseudo foreign key)

a seller can have one to several ads
an ad can be from only one seller

I made this query that gives me by day, the number of ads

select added_date,COUNT(adID) as nbad
FROM table_ad 
WHERE added_date >= '$sqldate_from' 
AND added_date <= '$sqldate_to'
GROUP BY added_date
ORDER BY added_date

I get :
2003-11-03 | 12
2003-11-04 | 22
2003-11-06 | 16

Is it possible to ad another colum to this result, showing the number of
unique seller ?

like this :
2003-11-03 | 12 | 3
2003-11-04 | 22 | 5
2003-11-06 | 16 | 2

without ressorting to a second query, a server side script or some
advanced SQL (MySQL < 4) ?

Cheers,
Damien COLA



More information about the thelist mailing list