SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simplify query select

    Hello everyone, I need your help.

    You can simplify this query in MySQL?

    Code:
    SELECT * FROM _tbl
       where 
         uo like '%M2%'
      or uo like '%M4%'
      or uo like '%M7%'
      or uo like ......
      or uo like ......
    Thanks in advance-

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by viki1967 View Post
    You can simplify this query in MySQL?
    no, sorry

    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    no, sorry


    Do you have something personal against me?

  4. #4
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,200
    Mentioned
    105 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by viki1967 View Post
    Do you have something personal against me?
    No, his point is that query cannot be simplified. It's not like when you're seaching for distinct values and you can use the IN operator.

    Using the LIKE forces each comparison to be done individually.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  5. #5
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    How can we simplify a query, when you don't give us the full query to begin with?

    From the looks of it, no is the answer.
    Ryan B | My Blog | Twitter

  6. #6
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rguy84 View Post
    How can we simplify a query, when you don't give us the full query to begin with?

    From the looks of it, no is the answer.
    Full query ?

    Code:
    SELECT * FROM _tbl
       where 
         uo like '%M2%'
      or uo like '%M4%'
      or uo like '%M6%'
      or uo like '%M7%'
      or uo like '%I1%'
      or uo like '%I5%'
      or uo like '%I6%'
      or uo like '%S1%'

  7. #7
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Ok, then i point to Dave's reply
    Ryan B | My Blog | Twitter

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    oh, wait, i think you could also do this ...
    Code:
    WHERE uo REGEXP 'M2|M4|M6|M7|I1|I5|I6|S1'
    but it will be just as inefficient as the LIKE solution
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    oh, wait, i think you could also do this ...
    Code:
    WHERE uo REGEXP 'M2|M4|M6|M7|I1|I5|I6|S1'
    but it will be just as inefficient as the LIKE solution
    Thanks for your help.


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
  •