...

View Full Version : need to add DISTINCT to SQL?!



jarv
07-27-2011, 04:24 PM
need to add: DISTINCT $tableName.booking_date

to my following SQL line below:

"SELECT COUNT(*) as num FROM $tableName WHERE booking_date BETWEEN '$from' AND '$to'"

please help

jarv
07-27-2011, 06:54 PM
can anyone help here?

Old Pedant
07-27-2011, 09:30 PM
I'm sorry, the question doesn't make sense, to me.

Are you saying you want a COUNT for each distinct booking_date??

In that case, you don't want DISTINCT, you want GROUP BY:


$sql = "SELECT booking_date, COUNT(*) as num "
. " FROM $tableName "
. " WHERE booking_date BETWEEN '$from' AND '$to' "
. " GROUP BY booking_date "
. " ORDER BY booking_date';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum