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.i d
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. 4 1476
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.i d 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.
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.i d
WHERE s.kind_id = '1'
GROUP BY s.id, s.name
ORDER BY s.name ASC
LIMIT 0, 20
Thank you * both * sooooo incredibly much!!!!!!!
You made my night :)
Greetings Frizzle. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 reduces the number of records
selected, do we really need to index field2 as well.
In other words, does the query first subselect from the first argumet,
|
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 switch
between the 2 and make best use of the indexes.
CREATE TABLE myTable(ID INT PRIMARY KEY CLUSTERED, COUNTY VARCHAR(50))
CREATE INDEX IDX_myTable_County ON myTable(COUNTY)
DECLARE @COUNTY VARCHAR(50)
SET @COUNTY = 'SANTA CLARA' -- Could...
|
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 columns,
and ultimately feed the result into a graph-drawing web thingy.
I'm trying a few different ways to get what seems to be the same data,
and seeing some odd behavior from the query planner.
The table looks like this:
|
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 it is used.
SQLSTATE=42703
SELECT DISTINCT S3.OPR_APPLICATION_NR,
S3.APPLICATION_ID,
S3.APPRAISAL_TYPE_CD,
S3.Appraisal_Used_Amount,
S3.RPT_LEVEL2_NR,
|
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
-------------------------
SELECT * FROM
( Select x.event_date From x FULL OUTER JOIN y
ON x.event_date = y.event_date
| |
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 , etc.
I want to go to the first row, do a WHERE statement, return the
|
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 DB table that will track the orderids requested
from Worldship so that I can stop doubleships. That is to set up a
function to allow the info to be sent only once to worldship.
I need to execute a stored procedure to write to a table and...
|
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 Server backend. There is a form in the .adp whose record source is a View which contains a WHERE clause.
My questions (and sorry these may be kinda basic):
- I am going to sort the view using a further query.. something like: "SELECT * from...
|
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 invalid use of null.
Fair enough Field1 and Field2 can contain nulls
I altered the 2 queries to exclude nulls from FasText and FasInteger-
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |