hi, I have a problem. I have 2 tables (shopping_cart,customer) that both have buyer_id. $query = "SELECT buyer_id FROM shopping_cart,customer WHERE shopping_cart.buyer_id=customer.buyer_id;"; $result = mysql_query($query) or die(mysql_error()); Code (markup): I get this error message: Column 'buyer_id' in field list is ambiguous Can you help me? I need to insert the buyer_id s to another table.
You need to qualify the buyer_id that you are selecting:- SELECT shopping_cart.buyer_id FROM shopping_cart,customer WHERE shopping_cart.buyer_id=customer.buyer_id Most people use aliases for the tables because it reduces the amount of keying of qualifications. So you could do the following:- SELECT s.buyer_id FROM shopping_cart s,customer c WHERE s.buyer_id=c.buyer_id
BTW. You need to qualify the buyer_id because SQL doesn't know which buyer_id you want in your select. Because you're joining the two tables by buyer_id, you can choose from either table.