我有一个包含两列的表格:
ID1 | ID2
---------
1 | A
3 | V
1 | C
4 | B
5 | Q
1 | S
我希望能够找出是否有任何行,例如ID1 = 5和ID2 = Q,并返回真/假值。
答案 0 :(得分:1)
是的,当然
SELECT * FROM table where ID1='5' and ID2='Q'
PHP (我只是猜测这个后端)
$query = "SELECT * FROM table where ID1='5' and ID2='Q'";
$result = mysql_query($query);
if(mysql_num_rows($result)) { return true; }
else { return false; }
答案 1 :(得分:0)
1
表示TRUE
代表mysql
SELECT 1
FROM your_table
WHERE ID1 = 5 AND ID2 = 'Q'
答案 2 :(得分:0)
例如这个?
SELECT 1
FROM TABLE
WHERE ID1 = 5 AND ID2 = 'Q'
答案 3 :(得分:0)
为您的目的进行高效查询(比其他示例更快):
SELECT 1 FROM table where ID1='5' and ID2='Q' LIMIT 1
PHP示例:
<?php
$query = "SELECT 1 FROM table where ID1='5' and ID2='Q' LIMIT 1";
echo bool(mysql_num_row(mysql_query($query)));
?>