'cushbu_mark_user_favorites' cushbu_users (id,first_name,last_name)
MySQLがトリプルエラーに参加し、私は私のデシベル</p> <p>1)で3つのテーブルを持っている
2)cushbu_art (id,user_id(FK cushbu_user),title,base_price etc...)
-forストアのユーザー芸術
3)cushbu_mark_user_favorites (id,user_id(FK cushbu_user),art_id(FK cushbu_art))
-forマーキングお気に入り項目
をお気に入り化(favourited)お気に入りのカウントはここ(
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
UPDATE
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
を得ました
だから不明なことは...?あなたは同じテーブルに複数回参加しているので、エイリアスを使用する必要があります。そのため、いつどのインスタンスを参照しているかわかりません。 – CBroe
@chiragsataparaは説明バージョンです。https:// stackoverflow .com/questions/45373911/mysql-joinget-total-favorites-for-each-row – Jabaa
確かに私はそれを受け入れるでしょう – Jabaa