Jump to content

[SOLVED] GROUP BY not working!!! aaaggghhh!!!!


Recommended Posts

Hey peeps

 

I'm really tearing my hair out over this one!!

 

I am developing a system at work. One table stores motorcycles, another stores their categories. Each bike can have many categories, hence the different tables.

 

RIGHT....

The system has to produce a stock list, and it lists bikes for each category. This is my SQL for the query to return a list of categories...

 

		$query_stock_cat_list = sprintf("SELECT vehicle_categories.name AS name FROM vehicle_categories LEFT JOIN vehicle_list
							  ON vehicle_list.vehicle_id = vehicle_categories.vehicle_id
							  WHERE vehicle_list.condition = %s
							  GROUP BY vehicle_categories.name",
		GetSQLValueString($condition, "text"));

	$stock_cat_list = mysql_query($query_stock_cat_list, $sql) or die(mysql_error());
	$row_stock_cat_list = mysql_fetch_assoc($stock_cat_list);
	$totalRows_stock_cat_list = mysql_num_rows($stock_cat_list);

 

When I run the script it lists the categories (good times) but repeats them so the 'Group by' does not appear to be working, bad times... the returned values are below, not sure what relevance that has but will include the results anyway...

 

Used Honda

Used Honda

Used European

Used Honda

Used European

Used Japanese

 

ANY help will be received with a lot of gratitude!

 

Ste xx

 

Link to comment
https://forums.phpfreaks.com/topic/166605-solved-group-by-not-working-aaaggghhh/
Share on other sites

Hi

 

Never really used a GROUP BY like that (would just use DISTINCT) but having a quick play it looks like it works.

 

As a quick simple check try the following:-

 

SELECT vehicle_categories.name, COUNT(*) FROM vehicle_categories GROUP BY vehicle_categories.name

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.