hi guys first time tackling inner join appreciated.
just wondering why getting following error code have created:
not unique table/alias: 'products'
here code itself:
mysql_select_db($database_reps, $reps); $query_orders = sprintf("select orders.id mainid, customers.`name` customername, products.productname product, orders.quantity quantity, orders.comment comment, orders.salesprice salesprice, orders.price price, orders.paid paid, orders.product2 product2, orders.ageofpayment ageofpayment, orders.orderdate orderdate, products.price productprice, staff.staffname staffmember, orders.bonus bonus orders inner join staff staff on orders.staffmember = staff.id inner join products products on orders.product = products.id inner join products products on orders.product2 = products.id inner join customers customers on orders.customername = customers.id orders.id = %s", getsqlvaluestring($colname_orders, "int")); $orders = mysql_query($query_orders, $reps) or die(mysql_error()); $row_orders = mysql_fetch_assoc($orders); $totalrows_orders = mysql_num_rows($orders); joins proving bit difficult appreciated.
inner join products products on orders.product = products.id inner join products products on orders.product2 = products.id both joins products table being aliased products, use different aliases each products1 , products2; , make sure use correct alias in list of selected columns; though select list doesn't give indication of want reference
edit
select orders.id mainid, customers.`name` customername, products1.productname productname1, products2.productname productname2, orders.quantity quantity, orders.comment comment, orders.salesprice salesprice, orders.price price, orders.paid paid, orders.product2 product2, orders.ageofpayment ageofpayment, orders.orderdate orderdate, products1.price productprice1, products2.price productprice2, staff.staffname staffmember, orders.bonus bonus orders inner join staff on orders.staffmember = staff.id inner join products products1 on orders.product = products1.id inner join products products2 on orders.product2 = products2.id inner join customers on orders.customername = customers.id orders.id = ...
Comments
Post a Comment