Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Returning results from just one table

Author  Topic 

bd528
Starting Member

23 Posts

Posted - 2011-07-19 : 05:51:18
Hi,

I'm running a query which cross references 4 different tables. I want the query to return all the fields from just one table. Unfortunately, there are more than 50 fields, so I cant specifiy them individually.
Is there any way to do this?

Thanks in advance.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-19 : 05:58:57
yes. you have to specify then one by one.

or get the column name from INFORMATION_SCHEMA.COLUMNS

select COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = '<your table name>'
ORDER BY ORDINAL_POSITION



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-19 : 06:04:43
Use alias name for table and use alias.*

select t1.* from table1 as t1 inner join table2 as t2 on t1.col=t2.col inner join ...


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

bd528
Starting Member

23 Posts

Posted - 2011-07-19 : 06:32:53
madhivanan, is there any way you could elaborate on your method, as I'm not yet familar with using INNER JOIN.

Thanks.
Go to Top of Page

bd528
Starting Member

23 Posts

Posted - 2011-07-19 : 06:54:34
Nevermind, I've managed to get the INNER JOIN working - perfect thanks.

khtan, thanks for your option. I'm sure I'll find that code useful in future.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-19 : 07:18:35
quote:
Originally posted by bd528

Nevermind, I've managed to get the INNER JOIN working - perfect thanks.

khtan, thanks for your option. I'm sure I'll find that code useful in future.


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -