Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 inner join error

Author  Topic 

morteza
Starting Member

1 Post

Posted - 2008-12-28 : 02:52:39
Dear all

i am writing this code to select first the maxmimun QTY from PUBS db
and then select the minimum one of this nested slect :


select a.min(qty),stor_id,ord_num,ord_date,payterms,title_id
from sales as s inner join(select max(qty),title_id from sales group by title_id)as a
on s.title_id=a.title_id
group by stor_id,ord_num,ord_date,payterms,title_id



when i run this code i got this error:
Server: Msg 8155, Level 16, State 2, Line 1
No column was specified for column 1 of 'a'.

please help me and tell me that what shoud i do?

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-12-28 : 09:30:20
You need to alias the calculated column inside the subquery. In a subquery, all returned columns must have defined names. If there's a function used as a column, that means you need to alias it.

Also, the a.min in the outer select should be min(a.qty)

So...
select min(a.qty),stor_id,ord_num,ord_date,payterms,title_id
from sales as s inner join(select max(qty) AS qty,title_id from sales group by title_id)as a
on s.title_id=a.title_id
group by stor_id,ord_num,ord_date,payterms,title_id


--
Gail Shaw
SQL Server MVP
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-12-28 : 15:24:19
You need to invest in a nuclear devolpent program

Good lord knows, an Oil fired sql server won't help



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2008-12-28 : 23:15:57
Do Just That...
your query.....Min(A.Qty),,,,your rest query
Go to Top of Page
   

- Advertisement -