LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-03-2007, 11:57 AM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
MySQL: Is there a clean way to do lots of AND/OR in a query?


I need to do a query something like:

select * from foo where bar not like "LA%" AND bar not like "ML%" AND bar not like "FA%" etc. etc.

There's 10 things I need to compare and that list may grow. Is there a cleaner way to do this? I saw a couple examples while googling around, but my need to look for non-matches seems to not work with those examples.
 
Old 08-03-2007, 12:16 PM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Maybe this:

SELECT * FROM foo WHERE NOT (LEFT(bar,2) IN ('LA','ML','FA'));

However this will be case sensitive, whereas the LIKE will be case-insensitive. I don't know if this will be a problem.
 
Old 08-03-2007, 12:32 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Guttorm
Hi

Maybe this:

SELECT * FROM foo WHERE NOT (LEFT(bar,2) IN ('LA','ML','FA'));

However this will be case sensitive, whereas the LIKE will be case-insensitive. I don't know if this will be a problem.
Perfect! Case sensitivity is not an issue in this case.

Thanks for the help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help with mysql query: return nth rows in query hawarden Programming 2 07-31-2006 06:36 PM
MySQL takes a lots of load ivanatora Linux - General 1 01-05-2006 06:53 AM
FreeeRadius and MySQL Need lots of help here alexus1 Linux - Software 11 10-22-2005 10:21 AM
Mysql Error: Lost Connection to Mysql during query ramnath Programming 5 11-18-2003 12:27 PM
Clean Redhat 8.0 install, starting MySQL Fenix Linux - Software 32 02-26-2003 08:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration