我需要的MySQL查詢得到其NID> 910 USER_ID = 1,NID> 902 used_id <> 1.
任何人做過這個項目?已搜索但無法找到它,因爲我是PHP和MySQL的新手。在WHERE
標準
我需要的MySQL查詢得到其NID> 910 USER_ID = 1,NID> 902 used_id <> 1.
任何人做過這個項目?已搜索但無法找到它,因爲我是PHP和MySQL的新手。在WHERE
標準
不能使用OR
:
SELECT *
FROM YourTable
WHERE (nid > 910 AND user_id = 1)
OR (nid > 902 AND user_id <> 1)
嘗試與此查詢:
SELECT * FROM items WHERE (nid>910 AND user_id=1) OR (nid>902 and user_id!=1)
SQL查詢:
SELECT * FROM table_name WHERE (nid>910 AND user_id=1) OR (nid>902 and user_id!=1);
但是,如果你想打電話它從PHP你需要這樣的事情:
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("exampledb",$dbhandle)
or die("Could not select exampledb");
//execute the SQL query and return records
$result = mysql_query("SELECT * FROM table_name WHERE (nid>910 AND user_id=1) OR (nid>902 and user_id!=1);");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'user_id'}." Nid:".$row{'nid'}."<br />";
}
?>