?
Solved

Construct a SELECT query

Posted on 2008-06-10
6
Medium Priority
?
750 Views
Last Modified: 2008-06-17
How do I construct a SELECT query with a WHERE CLAUSE?
For example:
I want to find all records with columnname that has an apple word in it.
I know this query is wrong.
SELECT * FROM TABLE1 WHERE COLUMNNAME is in ('APPLE TART', 'apple', 'apple pie', 'Candy Apple');

0
Comment
Question by:jramos74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:bolt81
ID: 21753347
SELECT * FROM table1 WHERE columnname LIKE '%apple%'

tutorial linked below
http://www.techonthenet.com/sql/like.php 
0
 

Author Comment

by:jramos74
ID: 21753367
Does the case format matter?  Will this query pull records with 'APPLE' too?
0
 
LVL 1

Expert Comment

by:bolt81
ID: 21753449
which version are you using?

you can use ILIKE if you are using version 10g
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:jramos74
ID: 21753743
Can you give me a select statement using ilike?  I tried it and it did not work.  We have 10g.  My query is SELECT * FROM TABLE1 where columnname ilike '%apple%' and it did not work.
0
 
LVL 1

Accepted Solution

by:
bolt81 earned 750 total points
ID: 21753837
SELECT * FROM table1 WHERE UPPER(columnname) LIKE ('%APPLE%')

the upper makes everything upper case so it will find apple and APPLE the % are wild cards so it will find apple in the middle of results as well e.g it will find "red apple" as well as "apple pie".

if you use _ this is a wild card for a single character eg 'APPLE_' will find apples but not bapples or red apple or apple pie

hope this helps
0
 
LVL 20

Assisted Solution

by:gatorvip
gatorvip earned 750 total points
ID: 21754092
ILIKE is a PostgreSQL keyword, not Oracle

You can also use  INSTR:

select *
from table1
where INSTR(lower(columnname), 'apple')>0

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question