| |
|
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.
|
 |

08-30-11, 18:42
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
|
|
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...
|
|

08-30-11, 19:13
|
|
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
|
|

08-31-11, 02:31
|
|
Registered User
|
|
Join Date: Dec 2008
Location: At work...
Posts: 68
|
|
|
|
Either use the LOWER function, or compare using a case-insensitive collation.
|
|

08-31-11, 02:32
|
|
Registered User
|
|
Join Date: Dec 2008
Location: At work...
Posts: 68
|
|
|
|

08-31-11, 08:45
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
|
|
Quote:
Originally Posted by r937
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.
|
|

08-31-11, 08:57
|
|
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.
|
|

08-31-11, 09:26
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
|
|
Quote:
Originally Posted by JarlH
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)
|
|

08-31-11, 09:33
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
|
|

08-31-11, 09:53
|
|
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.
|
|

08-31-11, 09:55
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
|
|
Quote:
Originally Posted by r937
|
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?
|
|

08-31-11, 12:35
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
Originally Posted by CarlosinFL
...WHERE LOWER(title) = '%administrator';
|
you're thinking of LIKE here, not equals
|
|

08-31-11, 12:36
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
Originally Posted by CarlosinFL
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
|
|

08-31-11, 12:59
|
|
Registered User
|
|
Join Date: Oct 2010
Location: Orlando, FL
Posts: 184
|
|
Quote:
Originally Posted by r937
which is why questions asked in the ANSI SQL forum rarely get the final solution in actual ANSI SQL code
|
That's very interesting!
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|