select - Selecting users in a SQL Server database which have only default children -


i'm trying figure out how many users in database have default parameters. i've got following query:

select top 4000 users.id   users   join streams on users.id = streams.userid   join playlists on streams.id = playlists.streamid   playlists.firstitemid = '00000000-0000-0000-0000-000000000000' 

i thought fine, realized not specific enough. currently, stream 2 playlists, 1 populated , 1 not, still selected. not select stream if of child playlists have firstitemid set value other '00000000-0000-0000-0000-000000000000'.

this additional select bit beyond me.. i've tried time, can't syntax. point me in right direction?

try like:

select top 4000 users.id   users   join (select playlists.streamid streams join playlists on streams.id = playlists.streamid         group playlists.streamid having max(cast(playlists.firstitemid varchar(36)) = '00000000-0000-0000-0000-000000000000') streamplaylists on users.id = streamplaylists.userid 

you need grouped subquery on playlists , streams. selecting playlists maximum firstitemid '00000000-0000-0000-0000-000000000000' excludes other (higher sorted) guids. guids can't min/maxed, cast varchar.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -