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 2000 Forums
 SQL Server Development (2000)
 Compare 2 tables, return 1

Author  Topic 

Knarf180
Starting Member

42 Posts

Posted - 2004-07-28 : 10:20:55
When you query against 2 tables such as Select * from Table1,Table2 where ... Your return from the statement will be the data from both tables. Is it possible to only return the data from Table1 without specifying every element in that table in place of the "*".

Let me try to explain better. I want to match some data from Table1 to Table2, I want to return the matching records from table1 only. I dont want to know anything about Table2. I want to be able to do this without specifying every field in Table1 which are to be returned, I just want the whole thing and nothing from Table2.

Any ideas?

Thanks,
- Frank

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-28 : 10:29:57
Select table1.* From table1, table2 where....

Corey
Go to Top of Page

mr_mist
Grunnio

1870 Posts

Posted - 2004-07-28 : 10:29:58
SELECT table1.* from table1, table2 where...

But really you should consider specifying column names, and using the ANSI join syntax

SELECT table1.moo, table1.moo2 FROM table1 INNER JOIN table2 ON table1.moo = table2.moo

-------
Moo. :)
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-07-28 : 10:31:20
I think everyone else here will agree with mr_mist that you should try to avoid using Select *

Corey
Go to Top of Page

Knarf180
Starting Member

42 Posts

Posted - 2004-07-28 : 10:40:09
Why avoid Select *? I'm running a report that uses pretty much all of the fields from the table. Is it faster for the database to repond to specified items then to return all?
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-07-28 : 11:33:55
"select * " is overkill when you only 'need' 1/2 columns
"select * " may prevent indices being used for efficient access paths....performance!!
"select * " will do unpredictable things if extra columns are subsequentially added into the table that may not necessarily be required by the application....esp with views and TEXT datatypes


search here for deeper thoughts on this subject.....99% of the arguement is one way....DON'T
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-07-28 : 12:00:48
Anything else to add to the list?

http://weblogs.sqlteam.com/brettk/archive/2004/04/22/1272.aspx



Brett

8-)
Go to Top of Page
   

- Advertisement -