If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Search For

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-30-11, 18:42
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Question Search For

Can you please show or help me how I can do the following search but make it case insensitive? I did a Google search and found the LIKE condition however I can't find an example as shown below.

Code:
SELECT * FROM dp_user WHERE user_name = 'Carlos';
Empty set (0.00 sec)
I want to be able to find either 'Carlos' or 'carlos' in my SQL statement but I can't find anything on Google that shows me how to correct my SQL statement...
Reply With Quote
  #2 (permalink)  
Old 08-30-11, 19:13
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
which database system are you using?

you posted in the ANSI SQL forum -- ANSI SQL is the "standard sql" language

often, ANSI SQL is not suficient to solve specific issues, such as case sensitivity
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-31-11, 02:31
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
Either use the LOWER function, or compare using a case-insensitive collation.
Reply With Quote
  #4 (permalink)  
Old 08-31-11, 02:32
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
[doube-post]
Reply With Quote
  #5 (permalink)  
Old 08-31-11, 08:45
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Quote:
Originally Posted by r937 View Post
which database system are you using?

you posted in the ANSI SQL forum -- ANSI SQL is the "standard sql" language

often, ANSI SQL is not suficient to solve specific issues, such as case sensitivity
I'm using PostgreSQL but assumed it was just something I could use ANSI SQL for.
Reply With Quote
  #6 (permalink)  
Old 08-31-11, 08:57
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
Have you tried

...where lower(user_name) = 'carlos'...
?

Or ...where user_name collate english_ci_ai = 'Carlos'...?

I don't know any PostgreSQL's collation names, just wrote english_ci_ai as an example.
Reply With Quote
  #7 (permalink)  
Old 08-31-11, 09:26
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Quote:
Originally Posted by JarlH View Post
Have you tried

...where lower(user_name) = 'carlos'...
?

Or ...where user_name collate english_ci_ai = 'Carlos'...?
I just tried the following and looks like it worked:

Code:
ide=# SELECT id, fname, lname, email, dob, title FROM users WHERE LOWER(fname) = 'carlos';

 id | fname  |  lname  |        email        |    dob     |         title          
----+--------+---------+---------------------+------------+------------------------
  1 | Carlos | Mennens | carlos@iamghost.org | 1979-05-25 | Database Administrator
(1 row)
Reply With Quote
  #8 (permalink)  
Old 08-31-11, 09:33
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 08-31-11, 09:53
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Now suppose I was trying to find a list of 'titles' which all contained the word 'administrator' in any case? I tried using the '%' to fill the gaps but it didn't work.

Code:
ide=# SELECT title FROM users;
          title           
--------------------------
 Database Administrator
 Linux Administrator
So I tried the following and I'm obviously missing something:

Code:
ide=# SELECT title FROM users WHERE LOWER(title) = '%administrator';
 title 
-------
(0 rows)
Sorry for my ignorance or stupidity but I'm just trying to learn and document as much as I can learn.
Reply With Quote
  #10 (permalink)  
Old 08-31-11, 09:55
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
So basically what this tells me is what I learn from that URL can't be copied over to database engines like MySQL or Oracle, correct?
Reply With Quote
  #11 (permalink)  
Old 08-31-11, 12:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by CarlosinFL View Post
...WHERE LOWER(title) = '%administrator';
you're thinking of LIKE here, not equals
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 08-31-11, 12:36
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by CarlosinFL View Post
So basically what this tells me is what I learn from that URL can't be copied over to database engines like MySQL or Oracle, correct?
absoposilutely, yes, it cannot

which is why questions asked in the ANSI SQL forum rarely get the final solution in actual ANSI SQL code
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 08-31-11, 12:59
CarlosinFL CarlosinFL is offline
Registered User
 
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
Quote:
Originally Posted by r937 View Post
which is why questions asked in the ANSI SQL forum rarely get the final solution in actual ANSI SQL code
That's very interesting!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On