开发者

Help with simplifying this MySQL query

I'm setting up a system that tracks daily challenges for a video game. There are 4 daily challenges and one weekly challenge. Each challenge gets saved to a table with an id, which can be reused it the challenge is ever re开发者_高级运维used (which they are, about 22% of the time). I've got another table to store each day's challenges, it looks like this:

date | daily1 | daily2 | daily3 | daily4 | expiration

Since challenges are reused, I'd like to be able to look up other days on which a challenge was used, by its ID. I'm using this query right now:

SELECT date FROM `current_daily`
  WHERE daily1 = #
    OR daily2 = #
    OR daily3 = #
    OR daily4 = #
  ORDER BY date ASC

It works, but it's so clunky. I'm trying to find a better was to run this query so I don't need all the ORs, but since it's getting information from multiple columns, it doesn't look like I can use IN(). Is there another way I could simplify this query and still get the same information?


You could use an IN to clean this up, but don't expect any performance gains from doing so.

SELECT date 
    FROM `current_daily`
    WHERE # IN (daily1, daily2, daily3, daily4)
    ORDER BY date ASC
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜