I looked around for a similar question, but if it exists, I haven't found it.
I do not believe this is a duplicate because I am trying to take multiple rows from TableB and combine with a single row from tableA, which is not something shown in the other question.
Consider the following tables.
|TableA |
|id value1|
|1 |3 |
|2 |10 |
|3 |10 |
|4 |6 |
|5 |10 |
|TableB |
|id Aid value2|
|1 |1 |14 |
|2 |1 |93 |
|3 |2 |30 |
|4 |3 |12 |
|5 |3 |62 |
|6 |3 |2 |
|7 |4 |2 |
|8 |4 |29 |
|9 |5 |50 |
I want each row FROM TableA WHERE value1=10, but I also want them joined with all the rows in TableB that have the id of those TableA rows as their Aid value.
Basically, I want to get back 3 rows: TableA rows 2, 3, and 5, where the 1st row is joined with TableB's 3rd row, the 2nd is joined with TableB's 4th, 5th, and 6th rows, and the 3rd is joined with TableB's 9th row.
How would I go about doing this? Is it even possible with one query? If it is possible, what would be the result?
This is about as far as I got...
SELECT a.*, b.* FROM TableA AS a JOIN TableB AS b ON a.id=b.Aid WHERE a.value1=10