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
 subquery

Author  Topic 

togy
Starting Member

5 Posts

Posted - 2009-03-27 : 18:07:43
i am using sql express and this script works well,

select id, name, image,
(select top 1 header from articles where journalist_id=journalists.id order by id desc)
from journalists order by que

i wanna get "body" column after the "header" column. but an error occurs;

"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."


thanks.

revdnrdy
Posting Yak Master

220 Posts

Posted - 2009-03-27 : 18:26:40
quote:
Originally posted by togy

i am using sql express and this script works well,

select id, name, image,
(select top 1 header from articles where journalist_id=journalists.id order by id desc)
from journalists order by que

i wanna get "body" column after the "header" column. but an error occurs;

"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."


thanks.



Try this


select id, name, image
from journalists
Where exists
(select top 1 header from articles where journalist_id=journalists.id order by id desc)
order by que


As far as how the data is presented you should handle that outside of the sql in the presentation layer (like the webpage or report).

r&r
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-28 : 02:59:31
quote:
Originally posted by togy

i am using sql express and this script works well,

select id, name, image,
(select top 1 header from articles where journalist_id=journalists.id order by id desc)
from journalists order by que

i wanna get "body" column after the "header" column. but an error occurs;

"Only one expression can be specified in the select list when the subquery is not introduced with EXISTS."


thanks.




select id, name, image,
(select top 1 header from articles where journalist_id=journalists.id order by id desc) as header,
(select top 1 body from articles where journalist_id=journalists.id order by id desc) as body,
from journalists
order by que
Go to Top of Page
   

- Advertisement -