I have two tables, that we'll call t1 and t2. I want to select the data in t1 that has a certain ID that I can only find using a where clause in t2. I don't want to select the data in t2 (many duplicate column names with different data) so how do I do that?
Asked
Active
Viewed 81 times
0
-
2If you are only concerned with duplicate column names, then why dont you join the two tables and in you select clause just select from the first table? – Jafar Kofahi Jul 18 '13 at 15:04
-
There are too many columns...I wanted to use select * – John Jul 18 '13 at 15:06
-
Yes you can use `T1.*` in your select statement which would read all the values from T1 only – Jafar Kofahi Jul 18 '13 at 15:12
2 Answers
3
try this
select * from t1 where t1.Id in (select distinct Id from t2)

Amit
- 15,217
- 8
- 46
- 68
-
Just what I was looking for- added the where clause after t2 (where column = columnValue) and it worked perfectly – John Jul 18 '13 at 15:05
0
Another approach is to join the tables
SELECT * FROM t1
JOIN t2 on t1.id = t2.id
You are joining them on a specific ID common between the 2 tables.

logixologist
- 3,694
- 4
- 28
- 46
-
That selects the data from t2 which has the duplicate columns with unique data – John Jul 18 '13 at 15:10