0

I have three huge tables each with many many columns (say 500 each).
Each of these tables joins together to form that data that I need by the 'USER_ID' field. What is the easiest way to select this without duplicating the "USER_ID" field 3x? I don't want to have to type out 'select table1.col1.....table3.col500'

my current query:

select table1.*, table2.*, table3.*
FROM table1
JOIN table2 on table1.user_id  = table2.user_id
JOIN table3 on table1.user_id =  table3.user_id

I'd like to do some sort of 'except table2.user_id, table3.user_id' in the select portion of the statement so I don't see this column there 3x...

jack
  • 102
  • 1
  • 6
  • No there is no such option in SQL. You have to type the columns you want. https://stackoverflow.com/search?q=%5Bsql%5D+select+all+except+one+column –  Jun 28 '17 at 06:12
  • @a_horse_with_no_name I think this can be done using dynamic SQL, but this might be out of scope for the OP. – Tim Biegeleisen Jun 28 '17 at 06:13
  • why dont you create the table with all columns and later drop the column that you dont want – Oasa Jun 28 '17 at 06:48
  • @TimBiegeleisen This is not a duplicate of the question you referenced. That question is about excluding a specific column (any) and this one is to exclude the join column that has a common name. In Postgres you can do that without dynamic sql with `select * from t1 join t2 using (colname)` – AlexYes Jun 28 '17 at 10:40
  • What version of SQL are you using? @AlexYes in MySQL this is not an option, perhaps it is in Postgres. Let the OP clarify his database and then we can reopen this question if necessary. – Tim Biegeleisen Jun 28 '17 at 11:28

0 Answers0