0

Instead of doing a query in SQL such as:

SELECT QUARTERSECTION WHERE
LABEL LIKE 'NE%' or LABEL LIKE 'SW%'

Is there anyway, I can a query to group values together LABEL LIKE IN ('NE%', 'SW%')?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
user2375756
  • 21
  • 1
  • 3
  • 1
    What RDBMS do you use? Some support regular expression matching, which can do what you want. But if it's just a few patterns to match, stick with `LIKE` and `OR`. – Michael Berkowski Apr 14 '15 at 18:56
  • 2
    And if they're all the same length, you could also use a truncated string with `IN`() as in `LEFT(LABEL, 2) IN ('NE', 'SW')` – Michael Berkowski Apr 14 '15 at 18:58

1 Answers1

1

You can create the temp table and put all like values there, then use Join

CREATE TABLE tempKeywordSearch (
  keyword VARCHAR(20)
);

INSERT INTO tempKeywordSearch  VALUES ('NE%'), ('SW%');

SELECT q.* 
FROM QUARTERSECTION q 
JOIN tempKeywordSearch t ON (q.col LIKE t.keyword);
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47