在join / order mysql中使用where where where

时间:2017-03-26 18:05:13

标签: mysql pdo


我真的不知道如何在这个SQL查询中使用“Where”条件 我应该使用这样的东西:

  

其中rules_id!= 6
  * rules_id = 6 =>禁止用户规则

	$stmt = $db_con->prepare("
	select * from users
	JOIN rules
	On users.rules_id = rules.rules_id
	order by rand() limit 1
");
谢谢,抱歉我的英语很差。

1 个答案:

答案 0 :(得分:1)

只需将其放在order by

之前
$stmt = $db_con->prepare("select * from users
                            JOIN rules On users.rules_id = rules.rules_id
                        where users.rules_id != 6 
                        order by rand() 
                        limit 1");