2

Q: If I have two tables joined together, and I want to get (*) from the first table, I mean all the fields of the first table.

Shall I write all the fields names of the first table in the query? Or is there some way to select * just from the first table.

user unknown
  • 35,537
  • 11
  • 75
  • 121
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392

3 Answers3

5

You should not to list all the fields, see the example:

SELECT DISTINCT t1.*
from T1
join t2 on condition
Oleg Dok
  • 21,109
  • 4
  • 45
  • 54
3

first_table.* should do the trick.

Sergey Kudriavtsev
  • 10,328
  • 4
  • 43
  • 68
2

Sounds more like a semi join. Consider rewriting e.g.

SELECT DISTINCT T1.*
  FROM T1 JOIN T2 ON T1.id = T2.id;

can be re-written as

SELECT *
  FROM T1
 WHERE id IN (SELECT id FROM T2);
Community
  • 1
  • 1
onedaywhen
  • 55,269
  • 12
  • 100
  • 138