开发者

PHP/SQL Juste a simple left join?

Table (ipvote)

PHP/SQL Juste a simple left join?

Table (pictures)

PHP/SQL Juste a simple left join?

What is the SQL que开发者_StackOverflow社区ry to retrieve all the images that were not voted for such ip '127 .0.0.1 '?

Thank you in advance, Jeremie.


SELECT * FROM pictures
WHERE NOT EXISTS (SELECT * FROM ipvote WHERE idPicture = picutres.id AND ip = "127.0.0.1")

The picutre does not come through if...
- Many people voted, including "127.0.0.1"
- Just "127.0.0.1" voted

The picture does come through if...
- No-one voted
- One/Many people voted, but not "127.0.0.1"

Additionally, the picture only appears once, regardless of how many people voted.


SELECT * FROM pictures
LEFT JOIN ipvote pictures.id = ipvote.idPicture
WHERE ipvote.ip != "127.0.0.1"

Something like that.


select id from pictures p where id not in (select idpicture as id from ipvote where ip='127.0.0.1')


SELECT * FROM `pictures` `p`
LEFT JOIN `ipvote` `iv`
ON `p`.`id` = `iv`.`idPicture` AND `iv`.`ip` != '127.0.0.1';

@Dems is right, check the comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜