开发者

How to add more than one WHERE statements in MySQL?

开发者 https://www.devze.com 2022-12-16 14:42 出处:网络
Can anyone give me some examples to make que开发者_StackOverflow社区ry which has more than one WHERE statements please?

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

精彩评论

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