SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: length in MYSQL

  1. #1
    Non-Member
    Join Date
    Feb 2005
    Posts
    737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    length in MYSQL

    Hello,

    I have a query whereby I want to output all records in the column file_name where the characters in file_name are less than 800 characters, with a few and and or statements

    PHP Code:
    SELECT *
    FROM db
    WHERE length
    (file_name) < 800
    AND jl LIKE '%b%'
    OR jl  LIKE '%a%'
    OR jl  LIKE '%c%'
    OR jl  LIKE '%d%'
    OR jl LIKE '%e%'
    OR jl  LIKE '%f%'
    LIMIT 50 
    I can't see where i'm going wrong though, as it seems to ignore the length rule? Anyone kindly advise?

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Use ( and ) to tell MySQL in what order to execute the AND's and OR's
    Code MySQL:
    SELECT *
    FROM db
    WHERE length(file_name) < 800
    AND (   jl LIKE '%b%'
         OR jl  LIKE '%a%'
         OR jl  LIKE '%c%'
         OR jl  LIKE '%d%'
         OR jl LIKE '%e%'
         OR jl  LIKE '%f%'
        )
    LIMIT 50


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •