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
 Database Design and Application Architecture
 select three diferent fields related to a common f

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: orders

here 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: 101
products_id: 13
orders_id: 101
products_id: 43
orders_id: 101
products_id: 1

so i have three rows with the same orders_id but different products_id

now 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
Go to Top of Page

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: orders

here 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: 101
products_id: 13
orders_id: 101
products_id: 43
orders_id: 101
products_id: 1

so i have three rows with the same orders_id but different products_id

now 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 select

SELECT order_id,product_Id
FROM products
WHERE 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 o
INNER JOIN products p
ON p.order_id=o.order_id
WHERE o.order_id=@Order_id
Go to Top of Page
   

- Advertisement -