Samus Aran
Programmer
Greetings,
I am looking for a way to do some SELECT and return only specific data from my database, here is an example of the data:
Here are the results I am expecting:
Results 1 (first SELECT):
NOTE:
[ul]
[li]The column name result must follow the following restrictions:[/li]
[ul]
[li]The name must be unique unless:[/li]
[ul][li]There is another entry of name with a different value1, in which case, all the different name/value1 combos must be returned (this is mostly shown with IDs 1, 2, 3, 4, 5, 6, 10, 14 in the table, IDs 7, 8, 9, 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li][/ul]
[/ul]
[li]The column value1 result must follow the following restrictions:[/li]
[ul]
[li]The value1 must return all different value1 entries (according to the name restrictions), but they must not be repeated (this is mostly shown with IDs 10, 11, 12, 13, 14, 15, 16, 17 in the table, IDs 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li]
[li]The column value2 result has no restrictions.[/li]
[/ul]
[/ul]
Results 2 (second SELECT):
NOTE:
[ul]
[li]The column name result must follow the following restrictions:[/li]
[ul]
[li]The name must be unique unless:[/li]
[ul][li]There is another entry of name with a different value1, in which case, all the different name/value1 combos must be returned (this is mostly shown with IDs 1, 2, 3, 4, 5, 6, 10, 14 in the table, IDs 7, 8, 9, 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li][/ul]
[/ul]
[li]The column value1 result must follow the following restrictions:[/li]
[ul]
[li]The value1 must return all different value1 entries (according to the name restrictions), but they must not be repeated (this is mostly shown with IDs 10, 11, 12, 13, 14, 15, 16, 17 in the table, IDs 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li]
[li]The column value2 result has no restrictions.[/li]
[/ul]
[li]The column value3 result must follow the following restrictions:[/li]
[ul]
[li]The value3 must be TRUE.[/li]
[/ul]
[/ul]
Unfortunately, I have no idea how to approach this.
May you help me out with this please?
Thank you for your time and help, it is greatly appreciated.
I am looking for a way to do some SELECT and return only specific data from my database, here is an example of the data:
Code:
+----+------+--------+--------+--------+
| ID | name | value1 | value2 | value3 |
+----+------+--------+--------+--------+
| 1 | aaaa | aaaa | Yes | True |
| 2 | aaaa | bbbb | Yes | False |
| 3 | aaaa | cccc | Yes | True |
| 4 | aaaa | dddd | Yes | False |
| 5 | aaaa | eeee | Yes | False |
| 6 | bbbb | NULL | Yes | True |
| 7 | bbbb | NULL | Yes | False |
| 8 | bbbb | NULL | Yes | True |
| 9 | bbbb | NULL | Yes | False |
| 10 | cccc | ffff | No | True |
| 11 | cccc | ffff | No | False |
| 12 | cccc | ffff | No | True |
| 13 | cccc | ffff | No | False |
| 14 | cccc | gggg | Yes | True |
| 15 | cccc | gggg | Yes | False |
| 16 | cccc | gggg | Yes | True |
| 17 | cccc | gggg | Yes | False |
+----+------+--------+--------+--------+
Here are the results I am expecting:
Results 1 (first SELECT):
Code:
+----+------+--------+--------+--------+
| ID | name | value1 | value2 | value3 |
+----+------+--------+--------+--------+
| 1 | aaaa | aaaa | Yes | True |
| 2 | aaaa | bbbb | Yes | False |
| 3 | aaaa | cccc | Yes | True |
| 4 | aaaa | dddd | Yes | False |
| 5 | aaaa | eeee | Yes | False |
| 6 | bbbb | NULL | Yes | True |
| 10 | cccc | ffff | No | True |
| 14 | cccc | gggg | Yes | True |
+----+------+--------+--------+--------+
NOTE:
[ul]
[li]The column name result must follow the following restrictions:[/li]
[ul]
[li]The name must be unique unless:[/li]
[ul][li]There is another entry of name with a different value1, in which case, all the different name/value1 combos must be returned (this is mostly shown with IDs 1, 2, 3, 4, 5, 6, 10, 14 in the table, IDs 7, 8, 9, 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li][/ul]
[/ul]
[li]The column value1 result must follow the following restrictions:[/li]
[ul]
[li]The value1 must return all different value1 entries (according to the name restrictions), but they must not be repeated (this is mostly shown with IDs 10, 11, 12, 13, 14, 15, 16, 17 in the table, IDs 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li]
[li]The column value2 result has no restrictions.[/li]
[/ul]
[/ul]
Results 2 (second SELECT):
Code:
+----+------+--------+--------+--------+
| ID | name | value1 | value2 | value3 |
+----+------+--------+--------+--------+
| 1 | aaaa | aaaa | Yes | True |
| 3 | aaaa | cccc | Yes | True |
| 6 | bbbb | NULL | Yes | True |
| 10 | cccc | ffff | No | True |
| 14 | cccc | gggg | Yes | True |
+----+------+--------+--------+--------+
NOTE:
[ul]
[li]The column name result must follow the following restrictions:[/li]
[ul]
[li]The name must be unique unless:[/li]
[ul][li]There is another entry of name with a different value1, in which case, all the different name/value1 combos must be returned (this is mostly shown with IDs 1, 2, 3, 4, 5, 6, 10, 14 in the table, IDs 7, 8, 9, 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li][/ul]
[/ul]
[li]The column value1 result must follow the following restrictions:[/li]
[ul]
[li]The value1 must return all different value1 entries (according to the name restrictions), but they must not be repeated (this is mostly shown with IDs 10, 11, 12, 13, 14, 15, 16, 17 in the table, IDs 11, 12, 13, 15, 16, 17 are not in the results because of that restriction).[/li]
[li]The column value2 result has no restrictions.[/li]
[/ul]
[li]The column value3 result must follow the following restrictions:[/li]
[ul]
[li]The value3 must be TRUE.[/li]
[/ul]
[/ul]
Unfortunately, I have no idea how to approach this.
May you help me out with this please?
Thank you for your time and help, it is greatly appreciated.