MySQL - NOT IN THEM

How can I in mysql check if a value is inside multiple fields in another table?

Sort of

SELECT * FROM table WHERE concat('%',value,'%') NOT LIKE IN(SELECT field FROM anothertable)

But I don’t think it’s right, right?

+5
source share
3 answers

The following query should do this.

SELECT DISTINCT t.* 
FROM   table t, 
       anothertable a 
WHERE  a.field NOT LIKE Concat('%', t.`value`, '%'); 
+2
source

No, not at all.

SELECT * FROM table WHERE NOT EXISTS (
    SELECT * from anothertable WHERE field LIKE CONCAT('%',value,'%')
)

probably do it. Assuming what valueis a column on table, but fieldis a corresponding column on anothertable, which may or may not contain valueas a substring.

, , anothertable . , , . MySQL anothertable table.

+2

If I understood your question correctly (assuming that you want to find the value from the table in two fields (field1 and field2) in the "other table"):

SELECT * 
FROM table t 
WHERE EXISTS (SELECT Count(*) FROM anothertable WHERE field1 LIKE concat('%',t,value,'%') OR field2 LIKE concat('%',t,value,'%')
0
source

All Articles