Selecting MYSQL rows with same field names and adding a prefix

前端 未结 2 1940
星月不相逢
星月不相逢 2021-01-21 05:08

I\'m trying to make a mysql query to select several tables and LEFT join them, however they all have same columns names \'user\' etc. I want to rename all the fields in this man

2条回答
  •  面向向阳花
    2021-01-21 05:48

    You cannot supply a shorthand to alias columns you must do it explicitly for each column name. In general anyway, it is typically recommended to name all columns explicitly in the SELECT list rather than using SELECT *, since it allows you to deterministically specify the column order, and protects you against accidentally pulling in a large BLOB later on if one ever gets added to the table ( or any other schema changes ).

    SELECT
      mod_backup_accounts.user AS account_user,
      mod_backup_subscriptions.user AS subscription_user,
      ...
      ...
    FROM
      mod_backup_accounts
      LEFT JOIN `mod_backup_subscriptions` ON `mod_backup_accounts`.subscription_id = `mod_backup_subscriptions`.package_id
    

提交回复
热议问题