-2

How can i use LIKE in this query?

I have a problem with the syntax.

$query="SELECT id,dediche FROM table_dediche WHERE dediche not in (select dedica as dediche from ".$row['nome']."_quotes)";

I have to eliminate sentences from the table using LIKE %%.

        $query="SELECT id,dediche FROM table_dediche WHERE dediche not in (select dedica as dediche from ".$row['nome']."_quotes)";
        $sql = mysql_query($query); //faccio la query

        echo "<select style='width: 515px; margin-bottom:7px;' id='frasi' name='frasi'>";
        while ($res = mysql_fetch_array($sql)){ //prendo il risultato della query
        echo "<option value=\"".$res['dediche']."\">".$res['dediche']."</option>";
        }
        echo "</select>";
    ?>

Thanks in advance.

Reverter
  • 130
  • 1
  • 8

2 Answers2

1

To eliminate sentences, I presume you are looking for NOT LIKE

For example

SELECT sentence FROM sentences WHERE sentence NOT LIKE '%once upon a time%';

That will obviously need to be changed to work with your table structure.

Ryan
  • 3,552
  • 1
  • 22
  • 39
0

If I understand you correctly you have one table with words (or more general text). This is your table $nome. Now you want to select all rows from another table table_dediche, where column dediche does not containt anything that is in the table $nome. Is this correct?

That is not possible, if you get the values from another table. There is nothing like combining like and in with the result of a subquery. You can have a look at MySQL LIKE IN()? where they solve that problem using an regex. Not sure if that works in your case.

Community
  • 1
  • 1
Seb
  • 1,521
  • 1
  • 12
  • 19