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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select * From... Using Joins.

Author  Topic 

Razzle00
Starting Member

35 Posts

Posted - 2007-03-05 : 11:47:03
Hi,

Is it possible to create a SELECT statement that can pull all the fields from from 1 table in a statement that has 2 or more tables joined together. I know it can be done with 1 table like this..

Select * From Table1


But can it be done in a statment like this..

SELECT <Need all fields from table1>,b.last_name,b.first_name,c.sales,c.ytdtotal
FROM table1 a INNER JOIN table2 b ON a.access=b.access INNER JOIN
table3 c ON a.access=c.access
ORDER BY b.last_name,b.first_name,a.id


where I want all fields from table1 and only specified fields from table2 and table3.

Thanks,

Razzle

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-05 : 13:22:46
The best way to do it is to list all the fields from the table, otherwise the results of your query will change unexpectedly when you add a new column or remove a column to or from the table. But, yes, you can do what you want with
SELECT a.*,b.last_name,b.first_name,c.sales,c.ytdtotal
FROM table1 a INNER JOIN table2 b ON a.access=b.access INNER JOIN
table3 c ON a.access=c.access
ORDER BY b.last_name,b.first_name,a.id
Go to Top of Page

Razzle00
Starting Member

35 Posts

Posted - 2007-03-05 : 14:15:34
Thanks snSQL, that is exactly what I needed. The particular query that I am coding needs to include all of the fields from the first table regardless if a field was changed or added. I always need the complete table structure for this application.
Go to Top of Page
   

- Advertisement -