phpmysqlmysqladmin

Combining database query request in a single statement


I have been told that my web server only allows 75,000 database queries request per hour. I'm wondering if combining query request would lessen the amount of queries or if it doesn't matter. It kind of feel like common sense, but I just want to make sure. Thanks.

$text1 = "text1";
$text2 = "text2";
$text3 = "text3";

SELECT text FROM table WHERE text = '$text1';
SELECT text FROM table WHERE text = '$text2';
SELECT text FROM table WHERE text = '$text3';

3 queries ^---

SELECT text FROM table WHERE 
text = '$text1' OR
text = '$text2' OR
text = '$text3';

1 query ^---

Is the above correct or wrong? Thanks.


Solution

  • It look OK. You also can use "IN", the you can write i little bit smaler.

    SELECT text FROM table WHERE 
    text  IN ('$text1', '$text2', '$text3');