I've a tricky question. I have a table with numbers:
- 37823782
- 37823782
- 37823782
- 38478934
- 90003922
And another table with prefixes:
- 378
- 3847
- 384
- 001
I want to find all numbers matching the longest prefix. I succeded with this code:
$result = mysql_query("SELECT numbers FROM table1 GROUP BY numbers") or die ("Query error code 1");
while($row = mysql_fetch_array($result))
{
$numbers =$row["numbers"];
$result2 = mysql_query("SELECT * FROM table2 WHERE '".$numbers."' LIKE CONCAT(prefix, '%') ORDER BY CHAR_LENGTH(prefix) DESC LIMIT 1");
while($row2 = mysql_fetch_array($result2))
{
// That's it
}
}
Now what i want to simply make the opposite thing. I want to find all numbers not matching any prefix. In short in the above example i made i should get "90003922". I thought to use NOT LIKE CONCAT (prefix, '%') but it's not working. Any idea?
this will help you!
[exept table][1] [1]: http://stackoverflow.com/questions/13160913/table-a-except-table-b-relating-more-than-one-column – Jan 06 '13 at 12:38
[except][1] [1]: http://stackoverflow.com/questions/13160913/table-a-except-table-b-relating-more-than-one-column – Jan 06 '13 at 12:40