SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 is my Query Right??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yonkouturko
Yak Posting Veteran

Philippines
59 Posts

Posted - 01/05/2013 :  08:41:27  Show Profile  Reply with Quote
SELECT Qty, Category, Description, Tpc_Price, Srp, Visibility, Low, Average, High
FROM Table_TPC_POSTING
ORDER BY Category
UNION
SELECT Qty, Category, Description, Tpc_Price, Srp, Visibility, Low, Average, High
FROM Table_TPC_POSTING
ORDER BY Description

im getting error like this
" Column 'Table_TPC_POSTING.Qty' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. "

i really don't understand right now sql Errors.. because im still new at this... PLEASE HELP ME...

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/05/2013 :  16:14:44  Show Profile  Reply with Quote
Just get rid of the first order by

SELECT Qty, Category, Description, Tpc_Price, Srp, Visibility, Low, Average, High
FROM Table_TPC_POSTING
ORDER BY Category
UNION
SELECT Qty, Category, Description, Tpc_Price, Srp, Visibility, Low, Average, High
FROM Table_TPC_POSTING
ORDER BY Description


Post your full query if this doesn't solve the issue.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/06/2013 :  10:32:01  Show Profile  Reply with Quote
hmm? whats the purpose of above two queries? they look same to me

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Yonkouturko
Yak Posting Veteran

Philippines
59 Posts

Posted - 01/06/2013 :  20:57:47  Show Profile  Reply with Quote
ahhh here are some of the data of Column CATEGORY and DESCRIPTION

Category Description
HARDDISK HardDisk 80GB IDE Desktop Seagate SP
MONITOR 15"LCD SP ASSORTED
MONITOR 17"LCD surplus ASSORTED
MONITOR 17"LCD surplus (Black)
MONITOR 17"LCD SAMSUNG SYNCMASTER SP
MONITOR 19"LCD SP ASSORTED
MONITOR 22"LCD SP ASSORTED
HARDDISK HardDisk 250 GB IDE SP Desktop Seagate
HARDDISK HardDisk 250 GB SATA BN Desktop Seagate
HARDDISK HardDisk 500 GB SATA Desktop (SURPLUS)
CASING PISONET CASING ONLY w/ out accessories
CASING PISONET CASING with accessories
VIDEO CARD VIDEO CARD 1 GB MANLI GEFORCE210 DDR3 64BIT PCI-E
CABLE UTP CABLE GRAY (Brand New)
MOTHERBOARD MOTHERBAORD (FOR AMD) MOBO AM2 w/ build-in VIDEO SP
HARDDISK HardDisk 40 GB IDE SP Desktop Seagate
CASING HIP MINI w/ PSU HFI-5R
MEMORY Memory 4 GB DDR3 SODIMM 1333 BN Kingston
MONITOR 15"LCD SURPLUS (Black)
MONITOR 15.6"LED AOC (Brand new)
MONITOR 19"LCD SP ASSORTED2
MONITOR 22"LCD SP ASSORTED1
MONITOR 22"LCD SP ASSORTED2
CASING CASING HIP MINI w/out PSU HFI-5R BN
MONITOR 17"LCD wide surplus
MONITOR 19"LCD SP ASSORTED3
MONITOR 19"LCD SP ASSORTED1
MONITOR 19"LCD SP ASSORTED4
HARDDISK HardDisk 80GB sata Desktop Seagate SP
HARDDISK HardDisk 320 GB SATA SP Desktop Seagate

NOW IF POSSIBLE... I WANT TO ALPHABETIZE EACH COLUMN..
THATS WHY i order each COLUMN and UNION them.....

PLease HELP ME OUT!!!

THANK YOU!!!!
Go to Top of Page

Yonkouturko
Yak Posting Veteran

Philippines
59 Posts

Posted - 01/07/2013 :  00:23:02  Show Profile  Reply with Quote

@VISAKH
i've figured Out my problem... but still thanks for your support!!!
i really appreciate all the learning !! :D

here's my sql

SELECT Qty, Category, Description, Tpc_Price, Srp, Visibility, Low, Average, High
FROM Table_TPC_POSTING
ORDER BY Category, Description

i really thought that i cudn't ORDER BY 2 fields at the same time...
silly me.. hahaha
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/07/2013 :  10:13:02  Show Profile  Reply with Quote
ok...now it makes sense

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000