Ask Experts Questions for FREE Help !
    ashley velez's Avatar
    ashley velez Posts: 67, Reputation: 1
    Junior Member

    Aug 11, 2010, 01:49 PM
    How to reference multiple tables in a SQL Server Query/select Statement
    When running a select statement select field1, field2, field3, field4 from table1

    The values for field2 and field3 are a "code"...

    The value of the code in field2 is in table2, and the value for the code in field3 is in table3

    Example: Field2=16 , In the employee table, There is a column employee_id. Where employee_id=16, first_name_x= Jane , Last_name_x= Doe

    So instead of having the value for field2=16, Id rather the output be Doe, Jane

    Another Example: Field3=AA ; In the table code_category, There is a column code_c. Where code_c=AA , description_x= Available for Adoption

    So instead of having the value for field3=AA, Id rather the output be Available for Adoption

    So, I would like to run a select statement that pulls up the values for field1-4... but substitutes the codes in field2&3 for the description...

    I hope you follow, sorry if I made this sound more confusing than it needed to be.

    Not sure if it matters, but I am doing this in SQL Server Management Studios.
    rpray2007's Avatar
    rpray2007 Posts: 319, Reputation: 23
    Full Member

    Aug 24, 2010, 11:14 AM
    I think you want to use a JOIN statement. will explain how this works. Basically, join statements allow you to lock down the value of one column in a certain field in one table while selecting rows given that value in other tables using a WHERE clause.

    Alternatively: If you are not concerned about speed, you can just throw everything just list all tables (comma separated) and use the where clause where you can specific table1.field1 = table2.field2 (for example)

    One more alternative is to use sub selects:
    SELECT c1 from t1 WHERE f1 in (SELECT f FROM t2 where y=w);

    Hope one of the above helps.

Not your question? Ask your question View similar questions


Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.

Check out some similar questions!

Recover deleted records from sql server [ 2 Answers ]

Hi I wanted to find out if it is possible to recover records that have been accidentally deleted from sql server 2000.Please help.

Vp to sql server [ 1 Answers ]

Front end Vb6.0, back end.. sql server 2005... connection.. can someone please help me with the code for login and password. When I change my password in sql server 2005 not connection to the vb plese help me

SQL server 2000 failing to install [ 1 Answers ]

Hi, I have been trying to install SQL server 2000 on my dell laptop running Windows XP SP2.When I execute the autorun file for the Developer version then I chose SQL sever 2000 components option, then install database serveroption, it hangs there and the installation never continues. When you...

Update of SQL Server database content [ 1 Answers ]

I have database in the web with SQL Server 7.0. Now how can I periodically update the content of the database by simply uploading text file containing the cumulative updates? Can anyone help?

SQL Server [ 1 Answers ]

Does anyone know where I can find a bit of a tutorial on the web about creating a database in SQL server 2000?

View more questions Search