MySql inserts from one table to another, where the field is not zero

I have a "phone book" table in which there are 1.5 M entries, some of the entries have a "phonenumber" field.

I want to copy all records that the "phonenumber" field is not empty into another table. even if it seems very simple, I cannot get it to work.

here is my code:

INSERT INTO phonebook2 (company,zip,city,address,tags,phonetype,phonearea,phonenumber)
SELECT company,zip,city,address,tags,phonetype,phonearea,phonenumber
FROM phonebook WHERE phonenumber != null && phonenumber != "";

I do not get any errors, but I get "0 lines". in manual search by records, I see NULL values ​​for the call number.

any suggestions?

** I tried to run the same query without the WHERE part, and it transfers all the records as it should.

+3
source share
3 answers

Use IS NOT NULLinstead != null.

: MySQL

+5

NOT NOT, != null

+2

NOT NOT

WHERE EXISTS (SELECT phonenumber
FROM  phonebook)
+1

Source: https://habr.com/ru/post/1794112/


All Articles