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
 Query involving 2 tables

Author  Topic 

Clay101
Starting Member

5 Posts

Posted - 2008-07-14 : 15:50:54
I have 2 tables; Vendor_Mast and Inventory_mast
My query is to try to find out all the items that Vendor X sells.
I am very new to SQL and have no idea how to go about getting the set result.

Can anyone assist with this one, please.

Thank you

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-14 : 15:52:19
You haven't provide enough information for us to give an exact answer, so all we can really say is to use a join between the two tables.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Clay101
Starting Member

5 Posts

Posted - 2008-07-14 : 15:58:36
Thank you for the reply.

In Table Inventory_Mast the Primary key is: item_num no FK are in use
In table Vendor_Master Primary Key is: vendor_num again no FK in use.

Is there a way in SQL Server 2005 to get the information I am looking for without using a Foreign Key?
Do you have a code example or were to find such an example of how to do this?

Thank you,
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-07-14 : 16:01:36
You do not need a foreign key in order to join tables together, however you should use foreign keys to protect your data.

So using your two tables, how are they related? If no columns relate to each other, then you can not join them together.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-15 : 03:12:32
SELECT *
FROM Inventory_Mast i
INNER JOIn Vendor_mast v
ON v.VendorID=i.VendorID

assuming you've VendorID in inventory table.Else use linking column you've
Go to Top of Page
   

- Advertisement -