2

When I JOINing to tables which both have 'id' column, I getting the result with 'id' not from the table I need. And both these table has a lot of columns so I don't want to type them all in my query. Is it posible to do something similar to css :not like SELECT table1.*, table2.*:not(id) FROM ...? Or maybe there is some other solution?

Thanks

artnikpro
  • 5,487
  • 4
  • 38
  • 40

3 Answers3

4

If you do not want a particular column from a table, then you cannot use the *, you have to type out all of the columns that you want to get.

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • 2
    Which one should probably do anyway, to ensure that a new column added to the table or view (or a reordering of existing columns) doesn't break the application. – cdhowie May 02 '13 at 14:56
-1

That select will be returning both id columns; it's your programming language's libraries that are presumably only giving you access to one.

That said, does

SELECT table2.*, table1.* ...

get you all the columns you need?

ysth
  • 96,171
  • 6
  • 121
  • 214
-2

I found a solution myself. Very simple. I just replaced my second table to the first place and first table now goes after JOIN. Seems mysql returns only the ID of the latest table.

Thanks everyone!

artnikpro
  • 5,487
  • 4
  • 38
  • 40