Hi all,
I have two tables, 'devices' and 'lads', that look like this:
devices
ladsCode:mysql> select * from `devices` where `team` = 'both' or `team` = 'sml'; +----+-----------+------+-------+ | id | name | team | order | +----+-----------+------+-------+ | 1 | Banana | sml | 1 | | 2 | Mandarin | sml | 2 | | 4 | Egg | sml | 4 | | 5 | Pineapple | both | 5 | | 6 | Cherries | both | 6 | +----+-----------+------+-------+ 5 rows in set (0.00 sec)
In `lads`, `dev_1` `dev_2` etc correspond to the `id ` of the fruit in `devices`.Code:mysql> select * from `lads` where `team` = 'sml'; +----+-------+------+-------+-------+-------+-------+-------+-------+ | id | name | team | dev_1 | dev_2 | dev_3 | dev_4 | dev_5 | dev_6 | +----+-------+------+-------+-------+-------+-------+-------+-------+ | 1 | JoeB | sml | 0 | 0 | 0 | 0 | 0 | 0 | | 2 | Rob | sml | 0 | 0 | 0 | 0 | 0 | 0 | | 3 | AlexJ | sml | 0 | 0 | 0 | 0 | 0 | 0 | +----+-------+------+-------+-------+-------+-------+-------+-------+ 3 rows in set (0.00 sec)
Now, what I want to do is when I query the lads table, only select the dev_# columns that match what is shown in the top query (i.e. only ones that are for the 'sml' or 'both' teams). Does that make sense? Any guidance would be much appreciated.
Thanks all!![]()







Bookmarks