Home > Archive > PHP SQL > August 2004 > Can't Use Group By
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can't Use Group By
|
|
|
| Hi all. I am trying to use the following SQL statement and for some
reason it doesn't work. I get the following error:
Warning: odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access
Driver] You tried to execute a query that does not include the
specified expression 'InventoryTag' as part of an aggregate
function., SQL state 37000 in SQLExecDirect in
C: wwwroot ShowNames.php on line 32
Error in SQL
Here is the SQL
Statement:
SELECT EQUIPMENT.[Invertory Tag] AS InventoryTag,
EQUIPMENT.Function,
EQUIPMENT.[Employee ID], EQUIPMENT.[Phone Jack ID] AS
PhoneJackID,
EQUIPMENT.[Jack Location] AS JackLocation, EQUIPMENT.[Node
Name] AS
NodeName, PC.Desktop, PC.[Invertory Tag], Employee.[last name,
first
name] AS FullName, Employee.[First Name] AS FirstName,
Employee.[Last
Name] AS LastName, Employee.[Employee ID] AS UID FROM
EQUIPMENT,PC,Employee WHERE PC.[Invertory Tag] = EQUIPMENT.[Invertory
Tag]
AND EQUIPMENT.[Employee ID] = Employee.[Employee ID] AND
(Employee.[First
Name] LIKE '%user%' OR Employee.[Last
Name] LIKE '%user%') GROUP BY
Employee.[Employee ID]
It looks kinda ugly, but I know for a fact that
it works fine until I
add the GROUP BY clause. Any help would be
appreciated. Thanks in
advance.
Riggz
----------------------------------------
The post originated from PHP
Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
| |
| Barand 2004-08-18, 3:57 pm |
| with Access (and many other DB's), if you select a field you have
to group by it if you have a group by clause and it isn't
aggregated.
So if you have
--------
SELECT a, b, c, SUM(d) as d FROM xyz GROUP BY a, b
--------
will fail, you need
--------
SELECT a, b, c, SUM(d) as d FROM xyz GROUP BY a, b, c
--------
hth
Barand
http://members.aol.com/barryaandrew...agridguide.html easy
data tables - and more
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums
|
|
|
|
|