开发者

How to add more than one WHERE statements in MySQL?

Can anyone give me some examples to make que开发者_StackOverflow社区ry which has more than one WHERE statements please?

I have the following query and I want to add 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'");

Thanks in advance.


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


Use:

AND privacy = 'public'


I don't know anything about MySql specifically, but it looks like you just need another AND statement:

$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'");


Change the WHERE to AND:

AND privacy = 'public'

In full, and made more readable:

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'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜