'How can I include a row after a WHERE clause?

I have a list of names

  1. Bobby
  2. Owen
  3. Lilly
  4. Omar
  5. Justin
  6. Jamey
  7. Oden

I would like to first get only the names that begin with 'o' so I wrote

WHERE name LIKE 'O%'

Which gave me

  1. Owen
  2. Omar
  3. Oden

I would then like to add names that end with 'y'

  1. Owen
  2. Omar
  3. Oden
  4. Bobby
  5. Lilly
  6. Jamey

But I am having difficulty figuring out how to do so. I am working in oracle btw.



Solution 1:[1]

You could also use the AND:

`WHERE name LIKE 'O%' AND name LIKE '%y'`

Solution 2:[2]

SELECT * FROM MY_TABLE  WHERE name LIKE 'O%'
UNION ALL
SELECT * FROM MY_TABLE  WHERE name LIKE '%Y'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wanz
Solution 2 Shaido