简体   繁体   English

从多列中选择数据

[英]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.我对 SQL 有点熟悉,并试图编写一个搜索查询来从两列的匹配中提取数据,但我很难在两列中搜索一个术语。

Imagine I have two columns - Ticker and Name.想象一下,我有两列 - Ticker 和 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.例如,您可以搜索 IBM 或 International Business 机器以获得相同的结果。

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.但我不确定如何将 g.name 合并到其中。

What can I do?我能做些什么?

Use OR :使用OR

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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