Is there any size limit on a MySQL query ?

Discussion in 'MySQL' started by Jona, Aug 7, 2007.

  1. #1
    I have a db/table which I query with a "huge" query string, and it's different
    each time it run ... And it also grows over time.

    So, is there any upper limit how large a query string can be?

    Sample:

    $MySQL = "
    SELECT id, title, name
    FROM table
    WHERE
    id <> '4' AND
    id <> '9' AND
    id <> '11' AND
    id <> '15' AND
    id <> '18' AND
    id <> '43' AND
    id <> '101' AND
    id <> '151' AND
    id <> '198' AND
    id <> '314' AND
    id <> '1104' AND
    id <> '12665' AND
    id <> '14334' AND
    ... a lot more same as above ... can be several hundred, and growing ...
    AND
    verified = '1'
    ORDER BY title ASC";
     
    Jona, Aug 7, 2007 IP
  2. Galen

    Galen Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    http://dev.mysql.com/doc/refman/5.0/en/packet-too-large.html
     
    Galen, Aug 7, 2007 IP
  3. Jona

    Jona Well-Known Member

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #3
    THANK'S !! Looks like I can use MB size queries :)
    So, I'm not in any trouble with some hundreds or even thousands of lines !
     
    Jona, Aug 7, 2007 IP
  4. omarabid

    omarabid Well-Known Member

    Messages:
    1,509
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    130
    #4
    it can reach up to 1GB, however, make sure the limit is well set.
     
    omarabid, Jul 8, 2010 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    There's 2 ways of dealing with this.

    The best method is to make another table with excluded id's.

    SELECT columns FROM my_table WHERE id NOT IN (SELECT id FROM exclude_these_ids_table);

    The other is to use something like this, but you will eventually run into the same problems.

    SELECT id, title, name
    FROM table
    WHERE
    id NOT IN('4','9','11','15',......);
     
    jestep, Jul 8, 2010 IP