473,326 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Short query question (Where clause ..)

Hi there,
I can not seem to figure out where
to put my WHERE clause in the next query:

SELECT s.id,
s.kind_id,
s.active,
s.name,
COUNT(p.id) AS 'quantity'
FROM pr_series s
LEFT JOIN pr_products p
ON p.series_id=s.id
GROUP BY s.id, s.name
WHERE s.kind_id = '1'
ORDER BY s.name ASC
LIMIT 0, 20

This gives me a mysql error, and i can't find out where to put "WHERE
s.kind_id = '1'". I'm new to the LEFT JOIN & GROUP BY things, i've read
about it but, as i said, can't get it to work ... :(
Are the WHERE and JOIN / GROUP BY parts not meant to be in 1 query?

Any help would be greatly appreciated ...

Greetings Frizzle.

Jul 26 '05 #1
4 1463
frizzle wrote:
Hi there,
I can not seem to figure out where
to put my WHERE clause in the next query:

SELECT s.id,
s.kind_id,
s.active,
s.name,
COUNT(p.id) AS 'quantity'
FROM pr_series s
LEFT JOIN pr_products p
ON p.series_id=s.id
GROUP BY s.id, s.name
WHERE s.kind_id = '1'
ORDER BY s.name ASC
LIMIT 0, 20

This gives me a mysql error, and i can't find out where to put "WHERE
s.kind_id = '1'". I'm new to the LEFT JOIN & GROUP BY things, i've read
about it but, as i said, can't get it to work ... :(
Are the WHERE and JOIN / GROUP BY parts not meant to be in 1 query?

Any help would be greatly appreciated ...

Greetings Frizzle.


Examples are shown all throughout the mysql manual if thats what you are
using. Try looking at the JOIN SYTAX page for more details (
http://dev.mysql.com/doc/mysql/en/join.html ).

Carl.

P.S. The WHERE should be before the GROUP BY clause.
Jul 26 '05 #2
Switch the GROUP BY and the WHERE:

SELECT s.id,
s.kind_id,
s.active,
s.name,
COUNT(p.id) AS 'quantity'
FROM pr_series s
LEFT JOIN pr_products p
ON p.series_id=s.id
WHERE s.kind_id = '1'
GROUP BY s.id, s.name
ORDER BY s.name ASC
LIMIT 0, 20

Jul 26 '05 #3
Thank you * both * sooooo incredibly much!!!!!!!
You made my night :)

Greetings Frizzle.

Jul 26 '05 #4
Sweet dreams... And for the following nights you might
take a look at this tool for automated query creation:
http://151.100.3.84/technicalpreview/

Aug 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: steve | last post by:
To gain performance, do I need to index ALL the fields in the where clause. Say we have a query like: select stuff from table where field1=.. and field2=... If field1 selection substantially...
14
by: joshsackett | last post by:
I have a WHERE clause that could be an "=" or a "LIKE" depending upon if the passed variable is populated or not. I would like to know the best way to write the WHERE clause to make it dynamically...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
2
by: Jim.Mueksch | last post by:
I am having a problem with using calculated values in a WHERE clause. My query is below. DB2 gives me this error message: Error: SQL0206N "APPRAISAL_LESS_PRICE" is not valid in the context where...
9
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ...
8
by: chrisdavis | last post by:
I'm trying to filter by query or put those values in a distinct query in a where clause in some sort of list that it goes through but NOT at the same time. Example: ROW1 ROW2 ROW3 ROW4 ,...
3
by: wjreichard | last post by:
OK ... I am using UPS Worldship that issues an ODBC query to my MS2K server ... Worldship can query either a table or a view and retreive shipping info for a supplied orderid. I need to create a...
0
by: webgirl | last post by:
I'm relatively new to SQL Server & looking for some guidance, if possible. I've been reading lots of different things & am a bit confused about some basics. I have an Access Project with SQL...
9
by: Yitzak | last post by:
Hi spent a few hours on this one wrote a query that joined on results of 2 other queries. Qry3 using Qry1 and Qry2 When I used Qry1.FasText <cstr(Qry2.FasInteger) in the where clause - got...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.