我在使用 MySQL 查询时遇到问题(我是新手,所以放轻松!)。我有一个包含电视节目的网站,并且想根据两个不同的操作(对于自定义时间表)选择两个日期之间播出的剧集(没问题)。基本上,如果用户正在关注(uses_follow_shows)或观看节目(user_watched),我想显示该剧集,所以我想我会像下面那样(query_on_follow OR query_on_watch),但这不起作用(我得到1200行而不是 3,它从 user_watched 获取每个现有行)。
我认为这个声明会这样做,但它没有,我不明白为什么
SELECT * FROM show_episode_airdate, show_episode, show_network, network, shows, users_follow_shows, user_watched
WHERE show_episode_airdate.airdate BETWEEN '2013-07-20' AND '2013-07-27'
AND ( show_episode.episode_id = show_episode_airdate.episode_id
AND shows.id = show_network.show_id
AND show_network.network_id = network.network_id
AND show_episode.imdb_id_show = shows.imdb_id
AND users_follow_shows.user_id = 2 AND shows.id = users_follow_shows.show_id
OR user_watched.user_id = 2
AND shows.id = user_watched.show_id
AND show_episode.episode_id = show_episode_airdate.episode_id
AND shows.id = show_network.show_id
AND show_network.network_id = network.network_id
AND show_episode.imdb_id_show = shows.imdb_id )
ORDER by network.network_id ASC
谁能告诉我怎么了?
谢谢!
编辑:
SELECT *
FROM show_episode_airdate join
show_episode
on show_episode.episode_id = show_episode_airdate.episode_id join
shows
on shows.imdb_id = show_episode.imdb_id_show join
show_network
on show_network.show_id = shows.id join
network
on show_network.network_id = network.network_id join
users_follow_shows
on shows.id = users_follow_shows.show_id join
user_watched
on shows.id = user_watched.show_id
WHERE show_episode_airdate.airdate BETWEEN '2013-07-20' AND '2013-07-27' and
(users_follow_shows.user_id = 2 or
user_watched.user_id = 2
)
ORDER by network.network_id ASC;