Help with MySQL Query syntax: ERROR #1066 - Not unique table/alias

后端 未结 1 820
终归单人心
终归单人心 2021-01-25 14:56

I have four tables, user, user_billingprofile, user_shippingprofile, and user_address.

user: userId,

相关标签:
1条回答
  • 2021-01-25 15:21

    Can you post the structure of your tables? Based on your query I'd say you need to consider changing it up a bit.

    That said you can fix your current query by adding a table alias like so:

    SELECT * FROM `user`
      JOIN `user_billingprofile`  ON `user`.`userId` = `user_billingprofile`.`userId`
        JOIN `user_address` AS user_billing_address ON `user_billingprofile`.`currentAddress` = `user_address`.`addressId`
      JOIN `user_shippingprofile` ON `user_shippingprofile`.`currentAddress` = `user_address`.`addressId`
        JOIN `user_address` AS user_shipping_address ON `user_shippingprofile`.`currentAddress` = `user_address`.`addressId`
    

    Note the AS clause I added. You'll probably need to alias the columns too (instead of SELECT * you likely will need SELECT user_shipping_address.address AS user_shipping_address_value, user_billing_address.address AS user_billing_address_value ... )

    Hope that helps!

    0 讨论(0)
提交回复
热议问题