Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Special query

Status
Not open for further replies.

lfarina

Programmer
Apr 25, 2005
6
US
Hello,

I am trying to use a command button on a form to allow a user to run a make-table query. The query is the problem. I have two tables, I need all the data from table A but only certain columns from table B. Both tables have a company_id that is used for the relationship. I can't just say Select * from both tables because then I get the company_id in two different columns, I dont' want that. Also The columns from table B that I do want aren't always the same, sometimes there may be 10 columns, other times there may be 80. What would I put in a SQL statement or code to say give me all columns except the company_id from table B without giving the actual column names that I do want? Thanks.
 
Just threw this together. Does this help?
I just created 2 tables each with a company_id field along with 3 other fields to test.

Code:
SELECT Table1.*, Table2.* INTO NewTable
FROM Table1 INNER JOIN Table2 ON Table1.company_id = Table2.company_id;
Code:
ALTER TABLE NewTable
DROP COLUMN Table2_company_id

:) -Andrew

alien.gif

[Signature modified by admin request]
-TAG
anongod@hotmail.com
'Drawing on my fine command of language, I said nothing.'
 
Thanks for the reply Andrew, it worked!
 
How would I change a column name? For the same new table the other company_id that I wanted to keep has the original table name attached to it I would like for it to simply read Company_Id.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top