简体   繁体   中英

selecting data from multiple columns

I have a basic question but I haven't been able to find answer. I am a little familiar with SQL and trying to write a search query to pull data from a match of two columns but I'm struggling to search for a term in two columns.

Imagine I have two columns - Ticker and Name. I want to search both and return matches if a match occurs in either one. For example, you can search IBM or International Business machine to get the same results.

Here's my query:

SELECT g.ticker, g.name 
FROM   "General" g 
WHERE  g.ticker ILIKE '%ibm%' 
LIMIT  25;

but I'm not sure how to incorporate g.name into it.

What can I do?

Use OR :

SELECT g.ticker, g.name 
FROM "General" g 
WHERE g.ticker ILIKE '%ibm%' OR g.name ILIKE '%ibm%'
LIMIT 25;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM