简体   繁体   中英

Select return more value than one to main select

Can you please help me? I have one main (SELECT), where I'm using more next select commands but inferior select return me more value than one.

SELECT table1.column1 
AS table.refer, table2.column2 AS table.value,
    --Here is my problem:
    (select count(table.column.id) FROM table1 
    left outer join table1 on table1.column1 = table.column 
    LEFT outer join table2 on table2.column2 = table1.column1
    LEFT OUTER JOIN table3 on table3.column3 = table2.column2
    WHERE table1.column1 = (23212 " This value contains more data) AND table2.column2 = value AND YEAR(table1.column1) = YEAR(GETDATE() GROUP BY table.refer)

FROM table1 left outer join table1 on table1.column1 = table.column 
LEFT outer join table2 on table2.column2 = table1.column1
LEFT OUTER JOIN table3 on table3.column3 = table2.column2

WHERE table1.name1 in (23210, 23211, 23212, 4882525, 67735166, 74605160) AND table2.name2 in (15739, 15744, 15743, 15741, 15735, 15745)    
GROUP BY table.refer, table.value

Important value from main select is table.refer. I need take only one table.refer for second select. But for all data.

I check cursor function for this or create new table for this select data or field[] but I don't know how do it. Please help me.

So, part of the problem is that you have a Group By int the subquery (the "inferior select). This would allow the select to have a single column (count(table.column.id)) but multiple rows for that column, one for each table.refer. If you think about it, you're asking for the results of the sub select to be a field in higher select. So it can only return a single value.

So I think you may want to just remove the Group By. This would return a single Count result for the sub query.

If that is not what you wanted but are expecting multiple values, then the subquery as a field would not be the way to go and would need better description of what you're trying to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM