sql - Inner join does not output id column -
i have query joins of different tables
select cust_name, order_no, order_status, pay_method, pro_name, cust_city customers inner join orders on customers.cust_id = orders.cust_id inner join pro_orders on pro_orders.order_id = orders.order_id inner join products on products.pro_id = pro_orders.pro_id order customers.cust_name asc
i trying output order_id
orders table & customer_id
customer table id column related other table relation not output
try below
select c.cust_id, c.cust_name,order_no,order_status,pay_method,pro_name,cust_city customers c inner join orders o on c.cust_id = o.cust_id inner join pro_orders po on po.order_id = o.order_id inner join products pr on po.pro_id = pr.pro_id order c.cust_name asc
it because cust_id column in both customers , order table. sql doesn't know table's cust_id should printed.
also 1 of best practices create aliases , use aliases in query. makes query more readable , less prone errors above.
Comments
Post a Comment