Reputation: 109
I have a DB over 1M entries and i need to perform a query in mysql. I have 2 colonn with 2 numbers. One is a long entreprise number and the other short entreprise number. Both numbers are related. For instance : a company will have a short number of 112233445 and long number of 11223344566777. What i need to do is to select all lines where short number is different of the beginning of long number. Can you help me ?
Upvotes: 0
Views: 36
Reputation: 522406
Use LIKE
:
SELECT *
FROM yourTable
WHERE long_num NOT LIKE CONCAT(short_num, '%')
If you also want to restrict results to long numbers which don't have 14 characters, then you can add a second condition to the WHERE
clause:
SELECT *
FROM yourTable
WHERE long_num NOT LIKE CONCAT(short_num, '%') AND
CHAR_LENGTH(long_num) <> 14
Upvotes: 1