0

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?

jarlh
44.9k8 gold badges52 silver badges68 bronze badges
asked Nov 30, 2017 at 11:37
3
  • 3
    not like... Commented Nov 30, 2017 at 11:39
  • 2
    Create a view instead. No need to store same data in several tables. Commented Nov 30, 2017 at 11:40
  • What is the error you get? Commented Nov 30, 2017 at 11:46

3 Answers 3

2

Try This

CREATE TABLE others AS (SELECT *
 FROM employees 
 WHERE last_name NOT LIKE 'K%');
Yogesh Sharma
50.2k5 gold badges30 silver badges53 bronze badges
answered Nov 30, 2017 at 11:50
Sign up to request clarification or add additional context in comments.

Comments

1

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.

answered Nov 30, 2017 at 11:58

Comments

0

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.

answered Nov 30, 2017 at 11:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.