0

I am working on a SQL query please this one is showing this error

Msg 116, Level 16, State 1, Line 2
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

This is the query

select 
   *,
   (select top 1 * 
    from tbl_Renewal 
    where supid = b.S_id 
      and Payed = 1 
    order by 
      renewalid desc) as result 
from 
    tbl_SuperAdmin as b 
inner join 
    tbl_Renewal as c on b.S_id = c.supid

Please check and give me the solution

Any other solution for this actual task

please find the bellow task brief detail

table 1 'tbl_SuperAdmin' having on filed

data like example

s_id name age gtc.......
1     abc  23 .........
2     cda  42 ..........

another table 2 having 'tbl_Renewal'

renewalid  renname date supid   Payed etc......
1          first   -     1        1    ........
2          first   -     2        1    ........
3          second -      1        0     ........
4          second -      1        1     ........
5          third-        1        1     ........

thanks pradeep

2 Answers 2

1

You can't put a * in single column value,

query should be something like this

select 
       *,
       (select top 1 COLUMNNAME from tbl_Renewal where supid=b.S_id and Payed=1) as result 
from tbl_SuperAdmin as b inner join tbl_Renewal as c on b.S_id=c.supid
Sign up to request clarification or add additional context in comments.

1 Comment

leave it this select top 1 COLUMNNAME from tbl_Renewal where supid=b.S_id and Payed=1 give the bellow solution if putting columname also duplicates are coming
0

cut it short to below sql

 select top 1 a.*,b.*

 from tbl_Renewal a inner join tbl_SuperAdmin as b

 on b.S_id=c.supid where a.Payed=1 order by b.renewalid desc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.