Connecting Tech Pros Worldwide Help | Site Map

Syntax Error ORDER BY GROUP BY

bilibytes's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: Europe
Posts: 128
#1: Jul 30 '09
Hello, i need some help i am getting this error:

Expand|Select|Wrap|Line Numbers
  1. You have an error in your SQL syntax;
  2.  check the manual that corresponds to your MySQL
  3.  server version for the right syntax to use near 
  4. 'GROUP BY w.location_id ORDER BY w.wine_id ASC' at line 1
the entire query code is:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.             w.wine_id AS wineId,
  3.              w.name AS wineName,
  4.              w.producer_id AS producerId,
  5.              p.name AS producerName,
  6.              w.date_bottled AS dateBottled,
  7.              w.color_id AS colorId,
  8.              wc.name AS colorName,
  9.              w.type_id AS typeId,
  10.              wt.name AS typeName,
  11.              w.quality_guarantee_id AS qualityGuaranteeId,
  12.              wqg.name AS qualityGuaranteeName,
  13.              w.location_id AS locationId,
  14.              l.name AS locationName,
  15.              l.country_id AS countryId,
  16.              c.name AS countryName 
  17.         FROM 
  18.              Wine AS w 
  19.              INNER JOIN Producer AS p ON (w.producer_id = p.producer_id) 
  20.              INNER JOIN WineQualityGuarantee AS wqg ON (w.quality_guarantee_id = wqg.quality_guarantee_id) 
  21.              INNER JOIN Location AS l ON (w.location_id = l.location_id) 
  22.              INNER JOIN WineColor AS wc ON (w.color_id = wc.color_id) 
  23.             INNER JOIN WineType AS wt ON (w.type_id = wt.type_id) 
  24.             INNER JOIN Country AS c ON (l.country_id = c.country_id)
  25.         GROUP BY 
  26.             w.location_id 
  27.         ORDER BY 
  28.             w.wine_id ASC

does any one have any suggestion?

thanks

bilibytes
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#2: Jul 31 '09

re: Syntax Error ORDER BY GROUP BY


Quote:

Originally Posted by bilibytes View Post

Hello, i need some help i am getting this error:

Expand|Select|Wrap|Line Numbers
  1. You have an error in your SQL syntax;
  2.  check the manual that corresponds to your MySQL
  3.  server version for the right syntax to use near 
  4. 'GROUP BY w.location_id ORDER BY w.wine_id ASC' at line 1
the entire query code is:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.             w.wine_id AS wineId,
  3.              w.name AS wineName,
  4.              w.producer_id AS producerId,
  5.              p.name AS producerName,
  6.              w.date_bottled AS dateBottled,
  7.              w.color_id AS colorId,
  8.              wc.name AS colorName,
  9.              w.type_id AS typeId,
  10.              wt.name AS typeName,
  11.              w.quality_guarantee_id AS qualityGuaranteeId,
  12.              wqg.name AS qualityGuaranteeName,
  13.              w.location_id AS locationId,
  14.              l.name AS locationName,
  15.              l.country_id AS countryId,
  16.              c.name AS countryName 
  17.         FROM 
  18.              Wine AS w 
  19.              INNER JOIN Producer AS p ON (w.producer_id = p.producer_id) 
  20.              INNER JOIN WineQualityGuarantee AS wqg ON (w.quality_guarantee_id = wqg.quality_guarantee_id) 
  21.              INNER JOIN Location AS l ON (w.location_id = l.location_id) 
  22.              INNER JOIN WineColor AS wc ON (w.color_id = wc.color_id) 
  23.             INNER JOIN WineType AS wt ON (w.type_id = wt.type_id) 
  24.             INNER JOIN Country AS c ON (l.country_id = c.country_id)
  25.         GROUP BY 
  26.             w.location_id 
  27.         ORDER BY 
  28.             w.wine_id ASC

does any one have any suggestion?

thanks

bilibytes

Is this your query as it exists in your code? If so, where is the ";" that is supposed to end the mysql statement?

Regards,

Jeff
bilibytes's Avatar
Familiar Sight
 
Join Date: Jun 2008
Location: Europe
Posts: 128
#3: Aug 3 '09

re: Syntax Error ORDER BY GROUP BY


thanks for your answer, but the ';' is automatically appended to the query when using mysql_query() from php.

I already solved the problem.

Regards,

bilibytes
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,565
#4: Aug 3 '09

re: Syntax Error ORDER BY GROUP BY


Quote:

Originally Posted by bilibytes View Post

thanks for your answer, but the ';' is automatically appended to the query when using mysql_query() from php.

I already solved the problem.

Regards,

bilibytes

Great! Congrats. Care to share the solution you discovered so we can all learn from it?

Thanks!

Jeff
Reply