Mysql三连接错误:不唯一的表/别名:'cushbu_mark_user_favorites'

时间:2017-07-28 09:36:33

标签: mysql node.js join sequence

我的数据库中有3个表

1)cushbu_users (id,first_name,last_name)

2)cushbu_art (id,user_id(FK cushbu_user),title,base_price etc...) - 用于商店用户艺术

3)cushbu_mark_user_favorites (id,user_id(FK cushbu_user),art_id(FK cushbu_art)) - 用于标记喜欢的项目

我想获取特定用户喜爱的所有艺术项目
 每个艺术的收藏数(存储在cushbu_mark_usier_favorites表中)

这是我的查询

SELECT
    cushbu_art.id AS art_id,
    cushbu_art.title,
    cushbu_art.base_price,
    cushbu_art.image_name,
    CONCAT(
        cushbu_users.first_name,
        ' ',
        cushbu_users.last_name
    ) AS artist_name,COUNT(cushbu_mark_user_favorites.art_id)
FROM
    cushbu_art
JOIN cushbu_mark_user_favorites ON cushbu_mark_user_favorites.art_id = cushbu_art.id
JOIN cushbu_users ON cushbu_users.id = cushbu_art.artist_id 
LEFT JOIN cushbu_mark_user_favorites ON cushbu_art.id=cushbu_mark_user_favorites.art_id
WHERE
    cushbu_mark_user_favorites.user_id = 68 

但我得到Not unique table/alias: 'cushbu_mark_user_favorites'这个join声明

LEFT JOIN cushbu_mark_user_favorites ON cushbu_art.id=cushbu_mark_user_favorites.art_id

更新

SELECT
    a.id AS art_id,
    a.title,
    a.base_price,
    a.image_name,
    CONCAT(
        c.first_name,
        ' ',
        c.last_name
    ) AS artist_name,COUNT(b.art_id)
FROM
    cushbu_art a
JOIN cushbu_mark_user_favorites b ON b.art_id = a.id
JOIN cushbu_users c ON c.id = a.artist_id 
LEFT JOIN b ON a.id=b.art_id
WHERE
    b.user_id = 68 

1 个答案:

答案 0 :(得分:0)

尝试以下查询。

new Function<Object, Object>() {
            @Nonnull
            public Object apply(@Nonnull Object object) {

希望这对你有所帮助。