×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Looking for specific data using SELECT

Looking for specific data using SELECT

Looking for specific data using SELECT

(OP)
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:

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:
  • The column name result must follow the following restrictions:
    • The name must be unique unless:
      • 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).
  • The column value1 result must follow the following restrictions:
    • 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).
    • The column value2 result has no restrictions.
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:
  • The column name result must follow the following restrictions:
    • The name must be unique unless:
      • 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).
  • The column value1 result must follow the following restrictions:
    • 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).
    • The column value2 result has no restrictions.
  • The column value3 result must follow the following restrictions:
    • The value3 must be TRUE.
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close