Vincent
Vincent

Reputation: 6188

force table name before field in select

SELECT *
FROM Table1 T1
LEFT OUTER JOIN Table2 T2 ON T1.CCONTACT_FK = T2 .CCONTACT_PK

Both tables have a date_createField, so when I use select *, date_createField is returned twice. I could solve this by changing my select to:

SELECT T1.date_createField, T2.date_createField
FROM Table1 T1
LEFT OUTER JOIN Table2 T2 ON T1.CCONTACT_FK = T2 .CCONTACT_PK

But is it possible to not specify the specifik fields (keep select *), and force the table name in front of the property?

I'm having this problem because I'm joining 2 tables with a lot of columns and some columns have the same name. I would like to use select * and still have a distinction between columns present in both tables. Is this possible?

Upvotes: 0

Views: 224

Answers (2)

Muhamamd Omar Muneer
Muhamamd Omar Muneer

Reputation: 885

May this will help you

SELECT T1.*, T2.* FROM Table1 T1 LEFT OUTER JOIN Table2 T2 ON T1.CCONTACT_FK = T2 .CCONTACT_PK

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

This is not possible you need to specify the column names or accept all columns. If this is a query you will execute often make a view which can be reused.

Upvotes: 2

Related Questions