I have 3 tables like this:
table_1
+-ID-+-table_3_id-+
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
+----+------------+
table_2
+-ID-+-table_1_id-+-name--+-value-+
| 1 | 1 | Name1 | Data1 |
| 2 | 1 | Name2 | Data2 |
| 3 | 1 | Name3 | Data3 |
| 4 | 2 | Name1 | Data1 |
| 5 | 2 | Name2 | Data4 |
| 6 | 2 | Name3 | Data5 |
| 7 | 3 | Name1 | Data6 |
| 8 | 3 | Name2 | Data2 |
+----+------------+-------+-------+
table 3 consists of IDs and other data that is irrelevant to this question. However, I need to be able to filter on table_3_id.
This is what I need: Table 2 has multiple rows that have information of the rows in table_1. I need to have a query that checks if there are duplicates in the 'data' column, which have the same 'name'. The result I need would be this (with a WHERE table_3_id = 1):
+-table_3_id-+-name--+-value-+-duplicate-+
| 1 | Name1 | Data1 | true |
| 1 | Name2 | Data2 | false |
| 1 | Name3 | Data3 | false |
+------------+-------+-------+-----------+
Or, if possible, only return the data from table_2 where it actually is a duplicate. The 'duplicate' field can be a count too, since I do know the amount of rows that have the same table_3_id.
I hope I have made my question clear enough. If it is not clear enough I will try to improve it. I have tried it with joins and subqueries, but my knowledge of SQL isn't enough to make an advanced query like this. I'd prefer this in a single query instead of multiple in PHP.