question

wash4 avatar image
wash4 asked

Select * and column in different tables.

Hello, I would like to ask, is there a way, how to join two tables ( from first I need all columns (around 80) and second I need just two columns)? One way is to write each record (column) I need but it is realy boring 80 columns..
selectjoinscolumns
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered
Whilst it is not best practice to use `select *`, you can specify which tables select a.*, b.col1, b.col2 from TableA a join TableB b on a.id= b.id will give you all the columns from the first table, but only those you've specified from the second.
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Super thanks! It is working!
0 Likes 0 ·
ThomasRushton avatar image
ThomasRushton answered
ISTR that, if you drag the table from SSMS's object explorer into a query window it writes out a list of all columns. I could, of course, be wrong. It's Sunday, and I've not got a SQL Server fired up to play with.
4 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ISTR >> I seem to recall +1 - even though you don't have SQL Server running. Sunday is no excuse!
1 Like 1 ·
hi fatherjack and thomasrushton experts dont be fight ....in words.....come with solution
1 Like 1 ·
Is "answering questions from the phone" a better excuse?
0 Likes 0 ·
ah, that would be acceptable.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.