I need to create table, which should I call Others. I want only employeers who names which having names start with any other letter, but not K
I wrote sthg like this:
CREATE TABLE others AS select * from employees WHERE last_name no like 'K%';
I found sthg like this idea but it doesn't work
I'm receiving errror about syntax. Can you help me? The second question: there is any other way to write it?
-
3not like...jarlh– jarlh2017年11月30日 11:39:12 +00:00Commented Nov 30, 2017 at 11:39
-
2Create a view instead. No need to store same data in several tables.jarlh– jarlh2017年11月30日 11:40:04 +00:00Commented Nov 30, 2017 at 11:40
-
What is the error you get?user330315– user3303152017年11月30日 11:46:48 +00:00Commented Nov 30, 2017 at 11:46
3 Answers 3
Try This
CREATE TABLE others AS (SELECT *
FROM employees
WHERE last_name NOT LIKE 'K%');
Comments
As @jarlh said in his comment, a view would serve the same purpose, but the data would only be stored once instead of twice, thus saving disk space. You could define the view as
CREATE OR REPLACE VIEW OTHERS AS
SELECT *
FROM EMPLOYEES
WHERE LAST_NAME NOT LIKE 'K%';
Best of luck.
Comments
I would recommend using just string functions. Here are two ways:
WHERE SUBSTR(last_name, 1, 1) <> 'K'
or:
WHERE last_name < 'K' or last_name >= 'L'
Although you can use LIKE
or REGEXP_LIKE()
for this, I like this simpler approaches.