Linked Questions

Popular Questions

SQL "All" Functionality?

Asked by At

This is probably a really easy question, it's just very hard to google a word like "All".

SELECT a.Id, Max(b.Number)
FROM Table1 a
JOIN Table2 b
    ON a.FK = b.Id

But I want to add a where clause that specifies that all b.Id's linked to an a.FK must have values. So basically I don't want to select the a.Id grouping of b.Id's where any of those b.Id's are null. Hope I made that clear, let me know if I need to elaborate. Thanks.

Edit - For some clarification (Changed the query above as well):

Id, FK
1   1
1   2
2   3
3   4
3   5
3   6

Table 2
Id   Number
1    1
2    NULL
3    10
4    20
5    30
6    40

I would want my query to show:

a.Id   Max Number
2      10
3      40

(Notice that a.Id = 1 doesn't show up because one of the b.Number fields is null)

Related Questions