我在SQL中有这个查询,我知道它写得非常糟糕。你们能帮助我以体面,正常的方式写作吗?
感谢。
select distinct R.*, X.LIKED
from Recipe R
left join (select distinct R.* , '1' as LIKED
from Recipe R, Likes L
where R.id = L.idRecipe
and L.email = 'dvader@deathstar.galacticempire') X
on R.id = X.id
答案 0 :(得分:0)
看起来你需要所有来自vader@deathstar.galacticempire喜欢标记的食谱
select R.*, likedR.LIKED
from Recipe R
left join (select distinct R.id , '1' as LIKED
from Recipe R
inner join Likes L on R.id = L.idRecipe
where
L.email = 'dvader@deathstar.galacticempire') likedR
on R.id = likedR.id
答案 1 :(得分:0)
感谢大家的帮助。
我能够通过此查询做我想要的事情:
select distinct R.*, X.LIKED, U.imgUrl
from User U, Recipe R
left join
(select distinct R.* , '1' as LIKED
from Recipe R, Likes L
where R.id = L.idRecipe and L.email = 'dvader@deathstar.ge') X
on R.id = X.id
where R.email = U.email
如果dvader的条目在另一个表中,使用连接,这将在一个表中加上我需要的所有信息加1个额外的列,或者为1或者为null。