I’m trying to create a (sqlite) query that will perform a GROUP BY but will not group anything with the value ‘unknown’. For example, I have the table:
id | name | parent_id | school_id |
1 | john | 1 | 1 |
2 | john | 1 | 1 |
3 | john | 1 | 1 |
4 | nick | 2 | 2 |
5 | nick | 2 | 2 |
6 | nick | 3 | 3 |
7 | bob | 4 | 4 |
8 | unknown | 5 | 5 |
9 | unknown | 5 | 5 |
10| unknown | 5 | 5 |
With the proper query with ‘GROUP BY name, parent_id, school_id’ I need the following rows returned:
id | name | parent_id | school_id |
1 | john | 1 | 1 |
3 | nick | 2 | 2 |
4 | nick | 3 | 3 |
5 | bob | 4 | 4 |
6 | unknown | 5 | 5 |
7 | unknown | 5 | 5 |
8 | unknown | 5 | 5 |
Any help would be greatly appreciated. Thanks!
You can’t easily do this with one statement but you can
UNIONthe results of two statementsGROUPthe list of all butunknownUNION) the list of allunknownSQL Statement
Note that I assume you have posted wrong
unknownid’s in your result