If you want to eliminate the 177
value, you have to do the following (see the fiddle here):
CREATE TABLE p (p_id VARCHAR (25));
and populate it:
INSERT INTO p VALUES
('110177'),
('110177T'),
('177');
and then run the following SQL:
SELECT * FROM p WHERE p_id LIKE '___177%';
Result:
p_id
110177
110177T
Note that the ___177%
(3 underscores) predicate here will pick up all values that have 3 characters (any single character) followed by 177 followed by any other characters or none.
This is due to the difference between the %
(percent) wildcard and _
(underscore) - the _
means that the placeholder represents one, and precisely one character whereas the %
wildcard represents 0 or more characters.
So, the 177
isn't picked up because it has no characters before the 177 - it's explained well here.
The !=
solution proposed by @Akina will also work but it implies knowing the values to be excluded in advance - my reading of your question is that you want to eliminate any really short product_id
s and not just particular ones!
If you have more sophisticated requirements, you should take a look at regular expressions - an example from PostgreSQL can be found here - MySQL documentation here.
p.s. welcome to the forum!