Recently, I was assigned the task of creating an auction system. During my work, I met with numerous cases when my SQL queries with contained joins were not executed due to ambiguous column names. Consider this (simplified) auction table structure:
table auction:
idnameuid (ID of the user who created the auction)
table item:
idnameuid (identifier of the user who added the item)aid (auction identifier on which the item is available)price (starting price)
table user:
table bid:
iduid (identifier of the user who posted the application)iid (position whose price has been raised)price (suggested price)
As you can see, there are many columns with conflicting names. Joining these tables requires the use of certain measures that will eliminate the ambiguity.
. -, , , a_id, i_id, bid b_i_id. , .
, , - :
SELECT `bid`.`id`, `user`.`name`, `bid`.`price`
FROM `bid`
JOIN `item` ON `item`.`id` = `bid`.`iid`
JOIN `user` ON `user`.`id` = `bid`.`uid`
JOIN `auction` ON `auction`.`id` = `item`.`aid`
WHERE `bid`.`price` > `item`.`price`
AND `auction`.`id` = 1
GROUP BY `user`.`id`
ORDER BY `bid`.`price` DESC;
, .
, , , , ? SQL-?