문제

how do I select specific columns from three different tables based on their primary key. I have three tables,

Table1 orders (orderID, CustomerID, productID, orderdate, ,order quantity order_description).
Table2 Customers(CustomerID, Fname, Lname, Email).
Table3 Products(ProductID, Productname, Product weight).

I would like a query where I can display a result for a specific order for a specific customer and only the product he orderred. so I would like a new result to display

Customer Fname, lname, product name, quantity, for based on the specific orderID. Thank you. Hopefully you understood my question, Sorry my English is very bad.

도움이 되었습니까?

해결책

Try this one out:-

SELECT 
    c.Fname, c.Lname, p.productname, o.quantity
FROM Orders o
JOIN Customers c on o.CustomerID = c.CustomerID
JOIN Products p on p.ProductID = o.ProductionID
WHERE o.OrderID = @OrderID

다른 팁

$sql = "SELECT c.Fname, c.Lname, p.Productname, o.orderquantity
FROM orders o
    JOIN Customers c ON o.CustomerID = c.CustomerID
    JOIN Products p ON o.productID = p.ProductID
WHERE o.orderID = '$orderID';";

Doing direct variable injection like that is BAD, but without knowing what db connection you're using, that should be enough to get you going in the right direction.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top