Hi,
I am getting the following error:
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
Column 'tags.id' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
when trying to execute the following query:
select tags.id, name, count(*) as count from taggings, tags where
tags.id = tag_id group by tag_id
The above query works fine on MySQL, but chokes on SQL Server.
Could anyone please help?
Thanks!
NM 4 12517
(ne******@gmail.com) writes:
I am getting the following error:
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
Column 'tags.id' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
when trying to execute the following query:
select tags.id, name, count(*) as count from taggings, tags where
tags.id = tag_id group by tag_id
The above query works fine on MySQL, but chokes on SQL Server.
SQL Server, like most DB engines, as well as ANSI SQL, that if your
SELECT list includes an aggregate such as COUNT(*), and there is no
OVER clause for the aggregate, then all unaggregated columns in the
SELECT list must appear in the GROUP BY list.
Change tag_id in the GROUP BY clause to tags.id or vice versa.
Apparently MySQL is lax on this point. As a matter of fact SQL Server
4.x also permitted columns to appear in the SELECT list, if they did
not appear in GROUP BY. Sometimes the result made sense, as here
where tags.id is one-to-one with tags_id. Sometimes you got screenfulls
of garbage when you expected two lines, because you had left out a
column in the GROUP BY clause. The feature was removed in SQL Server
6.0 (and Sybase System 10), missed by few.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx
Thanks for your prompt reply, Erland. Pardon my ignorance, but I'm
still not sure if I understood how to solve the problem (although I
think I understand what the problem is from your explanation).
I have two tables:
1. tags (with the primary key 'id' and an attribute 'name')
2. taggings (the primary key is 'id', the foreign key is 'tag_id')
The query string I'm using is:
select tags.id, taggings.tag_id, name, count(*) as count from taggings,
tags where tags.id = taggings.tag_id group by taggings.tag_id
How should the correct query look like?
Thanks so much in advance!
Erland Sommarskog wrote:
(ne******@gmail.com) writes:
I am getting the following error:
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
Column 'tags.id' is invalid in the select list because it is not
contained in either an aggregate function or the GROUP BY clause.
when trying to execute the following query:
select tags.id, name, count(*) as count from taggings, tags where
tags.id = tag_id group by tag_id
The above query works fine on MySQL, but chokes on SQL Server.
SQL Server, like most DB engines, as well as ANSI SQL, that if your
SELECT list includes an aggregate such as COUNT(*), and there is no
OVER clause for the aggregate, then all unaggregated columns in the
SELECT list must appear in the GROUP BY list.
Change tag_id in the GROUP BY clause to tags.id or vice versa.
Apparently MySQL is lax on this point. As a matter of fact SQL Server
4.x also permitted columns to appear in the SELECT list, if they did
not appear in GROUP BY. Sometimes the result made sense, as here
where tags.id is one-to-one with tags_id. Sometimes you got screenfulls
of garbage when you expected two lines, because you had left out a
column in the GROUP BY clause. The feature was removed in SQL Server
6.0 (and Sybase System 10), missed by few.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server 2005 at http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinf...ons/books.mspx ne******@gmail.com wrote:
The query string I'm using is:
select tags.id, taggings.tag_id, name, count(*) as count from taggings,
tags where tags.id = taggings.tag_id group by taggings.tag_id
How should the correct query look like?
select taggings.tag_id, name, count(*) as tag_id_count
from taggins join tags on taggings.tag_id = tags.id
group by taggings.tag_id, name
Explanations:
1) GROUP BY must include all unaggregated columns from the SELECT,
i.e. everything that is not a COUNT(), SUM(), etc. (Why doesn't
it implicitly assume this? Apparently, it used to let you leave
things out, but that caused more trouble than it was worth. The
short answer is "just give it what it wants".)
2) tags.id and taggings.tag_id are forced to be equal, so you only need
to include one of them. Optional but recommended, as it's simpler
and conserves bandwidth.
3) The join is changed from SELECT ... FROM A, B WHERE A.X = B.Y
to SELECT ... FROM A JOIN B ON A.X = B.Y
Optional but recommended, as it keeps join conditions separate from
each other, and from other restrictions (e.g. NAME LIKE '%ABC%'),
all of which makes the query easier to understand.
Thank you very much, Ed. I really appreciate how quickly you've help me
fix this problem!
Ed Murphy wrote:
ne******@gmail.com wrote:
The query string I'm using is:
select tags.id, taggings.tag_id, name, count(*) as count from taggings,
tags where tags.id = taggings.tag_id group by taggings.tag_id
How should the correct query look like?
select taggings.tag_id, name, count(*) as tag_id_count
from taggins join tags on taggings.tag_id = tags.id
group by taggings.tag_id, name
Explanations:
1) GROUP BY must include all unaggregated columns from the SELECT,
i.e. everything that is not a COUNT(), SUM(), etc. (Why doesn't
it implicitly assume this? Apparently, it used to let you leave
things out, but that caused more trouble than it was worth. The
short answer is "just give it what it wants".)
2) tags.id and taggings.tag_id are forced to be equal, so you only need
to include one of them. Optional but recommended, as it's simpler
and conserves bandwidth.
3) The join is changed from SELECT ... FROM A, B WHERE A.X = B.Y
to SELECT ... FROM A JOIN B ON A.X = B.Y
Optional but recommended, as it keeps join conditions separate from
each other, and from other restrictions (e.g. NAME LIKE '%ABC%'),
all of which makes the query easier to understand.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Albert |
last post by:
Hi guys, it's nice to join the forum. Can someone can help me?
After 2 years of using a program, i suddenly got this error. I tried
re-installing SQL but im still getting the message.
...
|
by: Jon LaRosa |
last post by:
Hi all -
I have a web application and I want to be able to do some basic error
handling. For example, here is one error I would like to catch and
display in a useful way for the user:
...
|
by: Luc Dal |
last post by:
Hello,
I've serious problem using ASP under WindowsXP sp2.
I get the following reply (sorry it's in french)
Erreur de compilation Microsoft VBScript error '800a0401'
Fin d'instruction...
|
by: Jon LaRosa |
last post by:
Hi all -
I have a web application and I want to be able to do some basic error
handling. For example, here is one error I would like to catch and
display in a useful way for the user:...
|
by: in da club |
last post by:
i get error '80040e14' from this codes..
sqlbul="select * from buyers where sesid="&session.SessionID
set rsbul=baglantim.execute(sqlbul)
if rsbul.eof then
|
by: Alan Murrell |
last post by:
Hello,
One of our web hosting clients is getting the following error when
someone tried to log in form their login page:
--- ODBC ERROR ---
Microsoft OLE DB Provider for ODBC Drivers error...
|
by: chug |
last post by:
I'm not a programmer but it's my job to solve this. Can someone help me
with this error message?
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
Syntax error (missing
operator)...
|
by: FayeC |
last post by:
I am getting the following error:
Microsoft JET Database Engine error '80040e14'
Syntax error (missing operator) in query expression ''FayeC'
user_email='whatever@none.com' user_compname='none'...
|
by: rwilki02 |
last post by:
All,
We are using a process that updates tables in SQL Server 2000. The process
gives the following error but the table is updated even though there is an error.
My question is why are the...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |