How to write a query that acces table only once
Hi everyone,
Lets say I have this table (table A):
PK | COL_1 | COL_2 |
---|---|---|
1 | A | 1 |
2 | B | 1 |
3 | C | 2 |
4 | A | 3 |
5 | D | 3 |
6 | E | 3 |
When I query this table I know the col_1 value (but I do not know the col_2 value) so I can have this WHERE clause:
SELECT *
FROM A
WHERE COL_1 = 'A';
But what I really want, is all the rows that have the same col_2 value as the col_2 values of the rows WHERE col_1='A'.
Normally to do that I would have a query with a join between table A and itself, as such :.
SELECT a1.* FROM
a a1 INNER