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 |
johnwayne77
Starting Member
1 Post |
Posted - 2008-09-21 : 16:24:12
|
hello!i'm implementing an e-commerce system to distribute key codes.right now i'm thinking of a sql syntax to do the following:i have a table: ordershere i have the orders_id field (unique for each order placed)with this orders_id field there may be more than one products ordered therefore in the products_id field i can have the following situation:orders_id: 101products_id: 13orders_id: 101products_id: 43orders_id: 101products_id: 1so i have three rows with the same orders_id but different products_idnow i want to grab the value of these products_id for the specified orders_id (p.s. i can provide the orders_id value already)any ideas? i'm a little stuck on this..thanks |
|
hey001us
Posting Yak Master
185 Posts |
Posted - 2008-09-21 : 17:03:27
|
you need to get all three products or just only one?hey |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-22 : 03:21:54
|
quote: Originally posted by johnwayne77 hello!i'm implementing an e-commerce system to distribute key codes.right now i'm thinking of a sql syntax to do the following:i have a table: ordershere i have the orders_id field (unique for each order placed)with this orders_id field there may be more than one products ordered therefore in the products_id field i can have the following situation:orders_id: 101products_id: 13orders_id: 101products_id: 43orders_id: 101products_id: 1so i have three rows with the same orders_id but different products_idnow i want to grab the value of these products_id for the specified orders_id (p.s. i can provide the orders_id value already)any ideas? i'm a little stuck on this..thanks
if you want all of them just do a simple selectSELECT order_id,product_IdFROM productsWHERE order_id=@Order_id @order_id is input value for order.if you want order details also do a simple join SELECT o.*,p.product_id,p.productname,...FROM orders oINNER JOIN products pON p.order_id=o.order_idWHERE o.order_id=@Order_id |
|
|
|
|
|