mysql - 重复的列名

时间:2016-05-17 23:34:05

标签: mysql store

概述:

  • 有2张桌子
  • 使用两个表格中的entry_id(这可以)加入它们
  • 将这些结果存储在tableStore中
  • 然后在tableStore中将这些值按field_id_13
  • 的降序排序

CODE:

SELECT * FROM 
    (SELECT * FROM
        (SELECT *  
            FROM exp_channel_data 
            LEFT JOIN exp_channel_titles 
            ON exp_channel_data.entry_id = exp_channel_titles.entry_id 
            WHERE field_id_13 > '1' 
            ORDER BY field_id_13 
            ASC LIMIT 6
    ) AS tableStore) 
AS tableStore 
ORDER BY field_id_13 DESC

错误:   - "重复列名称' entry_id'"

问题:   - 我如何修复上面的代码,以便错误不会发生?

2 个答案:

答案 0 :(得分:1)

我将废除所有无关的嵌套,而是将其简单地写为:

SELECT * FROM (
                SELECT ecd.entry_id,
                       ecd.field_id_13,
                       ecd.field_id_11,
                       ect.title
                FROM exp_channel_data ecd
                LEFT JOIN exp_channel_titles ect
                ON ecd.entry_id = ect.entry_id 
                WHERE ecd.field_id_13 > '1'
                ORDER BY ecd.field_id_13 ASC
                LIMIT 6
              )
ORDER BY field_id_13 desc;

答案 1 :(得分:0)

问题是重复列说明其中一个select语句需要更多定义。

    SELECT * FROM 
    (SELECT * FROM
        (SELECT exp_channel_data.entry_id, exp_channel_data.field_id_13, exp_channel_data.field_id_11, exp_channel_titles.title  
        FROM exp_channel_data 
        LEFT JOIN exp_channel_titles 
        ON exp_channel_data.entry_id = exp_channel_titles.entry_id 
        WHERE field_id_13 > '1' 
        ORDER BY field_id_13 
        ASC LIMIT 6
    ) AS tableStore) 
AS tableStore ORDER BY field_id_13 DESC