Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- A little help with "select group by"


mark_roach - 2:12 pm on Dec 19, 2011 (gmt 0)


If you just want the distinct values then use the DISTINCT keyword and drop the group by.

eg.

$sql = 'SELECT DISTINCT IF(SUBSTRING(ip.Item, 4, 4)="Room","Room",ip.Item) AS Item';
$sql .= ' FROM `it-pricelist` AS ip';

Alternatively if you also want to know how many of each type there are add count(*) to your select statement :

$sql = 'SELECT IF(SUBSTRING(ip.Item, 4, 4)="Room","Room",ip.Item) AS Item, count(*)';
$sql .= ' FROM `it-pricelist` AS ip';
$sql .= ' GROUP BY Item';


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4399281.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com