SQL problems with COUNT

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
voidstate
Forum Newbie
Posts: 8
Joined: Wed Jan 22, 2003 8:01 am

SQL problems with COUNT

Post by voidstate »

Hi

I am trying to write a query which gets details from a products db, and also the number of associated options from a productoption db.

The SQL I have is like:

Code: Select all

$query = '	SELECT products.image_thumb, 
					products.name, 
					products.ordercode, 
					products.short_desc, 
					products.mrp_price, 
					products.bigfish_price, 
					COUNT(productoption.optionId) 
					FROM  products, productoption
					WHERE products.category = ' . $this->category . ' 
					AND productoption.productId = products.productId 
					ORDER BY ' . $sortBy  .'
					GROUP BY products.productId';
What am I doing wrong? MySQL is not really throwing an error which tells me anything, just:
Error: You have an error in your SQL syntax near '(productoption.optionId) FROM products, productoption WHERE produc'
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

try using double quotes around the entire query and single quotes within.

Code: Select all

$query="SELECT * FROM  products 
WHERE category = '{$val}'";

- xisle
voidstate
Forum Newbie
Posts: 8
Joined: Wed Jan 22, 2003 8:01 am

Post by voidstate »

Thanks for the reply, but the problem was solved when I removed the space between count and the first bracket.

Gah! I hate coding sometimes!

:roll:
Post Reply