如何在MySQL中添加多个WHERE语句?

时间:2010-01-18 15:13:49

标签: mysql where

有人可以给我一些例子来进行查询,其中包含多个WHERE语句吗?

我有以下查询,我想添加WHERE privacy ='public'

$query = $this->db->query("SELECT DATE_FORMAT(eventDate,'%d') AS 
day,eventContent,eventTitle,id FROM eventcal WHERE eventDate BETWEEN 
'$current_year/$current_month/01' AND '$current_year/$current_month
/$total_days_of_current_month'");

提前致谢。

4 个答案:

答案 0 :(得分:3)

[..] WHERE privacy = 'public' AND (eventDate BETWEEN [..] )

答案 1 :(得分:2)

使用:

AND privacy = 'public'

答案 2 :(得分:2)

我对MySql一无所知,但看起来你只需要另一个AND语句:

$ query = $ this-> db-> query(“SELECT DATE_FORMAT(eventDate,'%d')AS day,eventContent,eventTitle,id FROM eventcal WHERE
eventDate BETWEEN'$ current_year / $ current_month / 01'
AND'$ current_year / $ current_month / $ total_days_of_current_month'
AND privacy ='public'“);

答案 3 :(得分:1)

将WHERE更改为AND:

AND privacy = 'public'

完整,并且更具可读性:

SELECT DATE_FORMAT(eventDate,'%d') AS day,
       eventContent,
       eventTitle,
       id
FROM   eventcal
WHERE  eventDate BETWEEN '$current_year/$current_month/01'
                     AND '$current_year/$current_month/$total_days_of_current_month'
AND    privacy = 'public'