jeudi 13 août 2015

mysql query using alias throws error

Running the following query

SELECT p.id as pid,p.name as pname, p.email,p.phone,p.created as pcreated,
p.updated as pupdated, GROUP_CONCAT(g.name) AS groups FROM ft_smsender_persons p 
JOIN ft_smsender_persons2groups AS p2g ON p.id = p2g.person_id JOIN ft_smsender_groups AS g ON g.id = p2g.group_id 
WHERE 1=1 AND deleted = 0 AND p.id as pid LIKE '%7%' OR pname LIKE '%7%' OR 
email LIKE '%7%' OR phone LIKE '%7%' OR pcreated LIKE '%7%' 
OR pupdated LIKE '%7%' OR groups LIKE '%7%' group by pname, email ORDER BY pid asc

gives me an error on p.id as pid LIKE '%7%'

If I use it like pid like %7%, it gives me an error saying pid is unknown column

The query is generated dynamically so I have very less scope how to fix it through my code; is there any way in mysql?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire