Quantcast
Channel: Select rows with same id but null and some other value in another column for that id - Database Administrators Stack Exchange
Browsing all 7 articles
Browse latest View live

Answer by ammu for Select rows with same id but null and some other value in...

I tried with this one...select a.username from (select username ,col2 from yourtablewhere col2 is null) a,(select username ,col2 from yourtable where col2 is not null) bwhere a.username=b.username;

View Article



Answer by Bosko for Select rows with same id but null and some other value in...

I would use the sub-query to select those usernames like:select usernamefrom dbo.yourtablegroup by usernamehaving sum(distinct case when col2 is not null then 1 else 2 end) = 3;

View Article

Answer by ypercubeᵀᴹ for Select rows with same id but null and some other...

Just another way to do it:; WITH cte AS ( SELECT username, col2, cnt_all = COUNT(*) OVER (PARTITION BY username), not_null = COUNT(col2) OVER (PARTITION BY username) FROM yourtable AS a )SELECT...

View Article

Image may be NSFW.
Clik here to view.

Answer by Paul White for Select rows with same id but null and some other...

Another solution:SELECT Y1.*FROM dbo.yourtable AS Y1WHERE Y1.username = ANY( SELECT Y2.username FROM dbo.yourtable AS Y2 WHERE Y2.col2 IS NULL INTERSECT SELECT Y3.username FROM dbo.yourtable AS Y3...

View Article

Answer by JGA for Select rows with same id but null and some other value in...

This one works too.SQL Fiddle demoI obtain C1 as the total rows for each username, C2 as the total null rows for each user name and I compare these values later. SELECT username, col2 FROM(SELECT...

View Article


Answer by Taryn for Select rows with same id but null and some other value in...

You should be able to use conditional aggregation to get the username with both a value in col2 as well as null.I'd suggest using a HAVING clause with the conditions. The query would be similar...

View Article

Select rows with same id but null and some other value in another column for...

I want to get only rows having a value NULL and some other value than NULL for a particular username column.If both rows have null for that particular username or both have some values other than null...

View Article
Browsing all 7 articles
Browse latest View live




Latest Images