Search code examples
sqlsql-like

SQL request doesn't work with 2 conditions using LIKE operator


I'm trying to make a double condition request like this :

SELECT id, statut, nom, nom_deux, email, email_deux, adresse, adresse_deux, ville, codepostal, role_clients
FROM sys_clients
INNER JOIN sys_clients_roles
ON statut = id_clients
WHERE sys_clients.statut = 1 
AND sys_clients.nom LIKE 'a%'
ORDER BY sys_clients.nom ASC;

When I use only

WHERE sys_clients.statut = 1

The sql request is correct and I have the result but when I add

AND sys_clients.nom LIKE 'a%'

It's not working and I have a HTTP error 500. I want to avec all 'nom' begining by an 'a' letter.

Can you help me please ? Thanks


Solution

  • could be a problem is related to use of (single) quote be sure you have double quote around your sql code

    $sql ="SELECT id
          , statut
          , nom
          , nom_deux
          , email
          , email_deux
          , adresse
          , adresse_deux
          , ville
          , codepostal
          , role_clients
      FROM sys_clients
      INNER JOIN sys_clients_roles ON statut = id_clients
      WHERE sys_clients.statut = 1 
         AND sys_clients.nom LIKE  'a%'
      ORDER BY sys_clients.nom ASC;"