3 回答
TA贡献2019条经验 获得超9个赞
SELECT * FROM test WHERE texte LIKE '%something%' LIMIT 1
带着 mysql_num_rows()
:0.039061069488525 (更快)
SELECT count(*) as count FROM test WHERE text LIKE '%something%
:16.028197050095s。 SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%')
:0.87045907974243。 SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%' LIMIT 1)
:0.044898986816406 s。
SELECT * FROM test2 WHERE id ='321321' LIMIT 1
带着 mysql_num_rows()
:0.0089840888977051。 SELECT count(*) as count FROM test2 WHERE id ='321321'
:0.00033879280090332 s。 SELECT EXISTS(SELECT 1 FROM test2 WHERE id ='321321')
*0.00023889541625977 SELECT EXISTS(SELECT 1 FROM test2 WHERE id ='321321' LIMIT 1)
*0.00020313262939453 (更快)
TA贡献1807条经验 获得超9个赞
例子:
mysql> SELECT * FROM table_1;
+----+--------+
| id | col1 |
+----+--------+
| 1 | foo |
| 2 | bar |
| 3 | foobar |
+----+--------+
3 rows in set (0.00 sec)
mysql> SELECT EXISTS(SELECT 1 FROM table_1 WHERE id = 1);
+--------------------------------------------+
| EXISTS(SELECT 1 FROM table_1 WHERE id = 1) |
+--------------------------------------------+
| 1 |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT EXISTS(SELECT 1 FROM table_1 WHERE id = 9);
+--------------------------------------------+
| EXISTS(SELECT 1 FROM table_1 WHERE id = 9) |
+--------------------------------------------+
| 0 |
+--------------------------------------------+
1 row in set (0.00 sec)
使用别名:
mysql> SELECT EXISTS(SELECT 1 FROM table_1 WHERE id = 1) AS mycheck;
+---------+
| mycheck |
+---------+
| 1 |
+---------+
1 row in set (0.00 sec)
添加回答
举报