I have two tables.
T1 has one column which has 9000 unique records (varchar).
T2 has many columns with upwards of 1 million records. One of the columns T2.x of T2 has data from T1’s column T1.x, however some T2 records have in their column T2.x data that doesn’t exist in T1’s column T1.x. T2.x is also able to be NULL.
I want to list all records of T2, where T2.x has a record that matches T1.x
I tried = SELECT t1.column_x, t2.* from t1, t2 WHERE x = t1.x
However, this only lists 9000 records disregarding the many others that exist in T2.
How can I achieve what I seek?
e.g.
**t1 [x]
===**
a
b
c
**t2
===** [x]
1 .. .. .. a
2 .. .. .. b
3 .. .. .. eee
4 .. .. .. NULL
5 .. .. .. c
6 .. .. .. a
7 .. .. .. c
I want to get: 1-2-5-6-7
Thank you.
Quite simply the following will work, though it will cause performance issues on that size of table considering both
xcolumns are VARCHAR.Do you have an index on the
xcolumn already in botht1andt2, as if so that would help improve query speed. I would recommend NOT running this query in a production environment. If unavoidable, I would have to recommend includingLIMIT 10(or however many rows you need) in order to limit the impact.