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.
Author |
Topic |
geomark
Starting Member
3 Posts |
Posted - 2007-09-21 : 16:28:30
|
I need help writing a sql command to join data from 4 tables. Here is the structure of my tables:Table Primary KeyCATEGORIES CATEGORY_SIDITEMS ITEM_SID CATEGORY_SIDWAREHOUSES WAREHOUSES_SIDWAREHOUSES_ITEM_XREF WAREHOUSES_SID ITEM_SIDI want to be able to write a single query which would join all of these tables but I am not sure if I need a UNION or JOIN or SUBQUERY.I tried many variations but was not successful. Can someone point out the proper way to perform this command?Thank you. |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-09-21 : 16:56:14
|
well on which columns are they supposed to be joined?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
geomark
Starting Member
3 Posts |
Posted - 2007-09-21 : 17:16:36
|
I want to join the WAREHOUSES table to the ITEMS table using the ITEM_SID in the WAREHOUSES_ITEM_XREF table. I also want to pull the CATEGORY_SID from the CATEGORIES table using the ITEM_SID.Hope this is clear. I just want to be able to output data as one view from these multiple tables using the primary keys. |
 |
|
geomark
Starting Member
3 Posts |
Posted - 2007-09-21 : 17:43:55
|
I will try to simplify this. What I am actually trying to do is produce a recordcount of items in a particular warehouse. I am having trouble since I have to refer to multiple tables.I want to get the items from the items table and group them by warehouse using the warehouses_item_xref table. Is there a way I can use the Group By command in my query? |
 |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-21 : 23:43:50
|
quote: Originally posted by geomark I will try to simplify this. What I am actually trying to do is produce a recordcount of items in a particular warehouse. I am having trouble since I have to refer to multiple tables.I want to get the items from the items table and group them by warehouse using the warehouses_item_xref table. Is there a way I can use the Group By command in my query?
You can use group by to do a count of an aggregate function such as count(). Can you also provide all the columns you want in the select list? Future guru in the making. |
 |
|
|
|
|