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 |
|
maineman
Starting Member
7 Posts |
Posted - 2012-01-31 : 15:29:02
|
| Hi,Im having trouble connecting the following tables:Item+-------------+--------------+------+-----+----------------+| Field | Type | Null | Key | Extra |+-------------+--------------+------+-----+----------------+| itemID | int(11) | | PRI | auto_increment || name | varchar(64) | | | || description | varchar(128) | YES | | || categoryID | int(11) | YES | | |+-------------+--------------+------+-----+----------------+Category+-------------+--------------+------+-----+----------------+| Field | Type | Null | Key | Extra |+-------------+--------------+------+-----+----------------+| categoryID | int(11) | | PRI | auto_increment || name | varchar(64) | | | |+-------------+--------------+------+-----+----------------+ItemOrderMembership+-------------+--------------+------+-----+----------------+| Field | Type | Null | Key | Extra |+-------------+--------------+------+-----+----------------+| orderID | int(11) | | | || itemID | item(11) | | | |+-------------+--------------+------+-----+----------------+I need the orderID from ItemOrderMembership but not sure how to join the tables correctly. Can anyone show me? Thanks |
|
|
maineman
Starting Member
7 Posts |
Posted - 2012-01-31 : 15:48:15
|
| In other words how would you write a query to join these tables? |
 |
|
|
maineman
Starting Member
7 Posts |
Posted - 2012-01-31 : 16:40:07
|
| What I need is a query that will give me the name from the item table and category table where the orderid = 12345 for example. Any help appreciated. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-31 : 16:44:55
|
its just a simple inner join among tablesSELECT i.name AS ItemName,c.name AS CategoryNameFROM ItemOrderMembership iomINNER JOIN Item iON i.itemID = iom.itemID INNER JOIN Category cON c.categoryID = i.categoryID WHERE iom.OrderID = 12345 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|