Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
amaaiia
Super User
Super User

T-SQL do a SELECT from SELECT

I have an A table in a warehouse. I want to query the table as follows:

 

select STRING_AGG(field1, ',') from (select distinct field1 from [lakehouse].[schema].[table] where field2='value2')
 
And I get this error message: 
amaaiia_2-1710261474523.png

 


Is it possible to query a subquery? How can I get distinct values and then get them as a string separated by ','?

 

1 ACCEPTED SOLUTION
AndyDDC
Super User
Super User

Hi @amaaiia @can you try putting your select in a CTE:


;with distinctdata 

as

(

select distinct field1 from [lakehouse].[schema].[table] where field2='value2'

)

select STRING_AGG(field1, ',') from distinctdata

View solution in original post

1 REPLY 1
AndyDDC
Super User
Super User

Hi @amaaiia @can you try putting your select in a CTE:


;with distinctdata 

as

(

select distinct field1 from [lakehouse].[schema].[table] where field2='value2'

)

select STRING_AGG(field1, ',') from distinctdata

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Fabric Update Carousel

Fabric Monthly Update - September 2025

Check out the September 2025 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.