dimanche 1 mars 2015

How to do two `WHERE` commands


The following is the code I am working on.



SELECT *, COUNT(1) AS `items` FROM dbName WHERE user='$email' GROUP BY `lastname`,`firstname`,`address`


What I am trying to accomplish is to have the WHERE to remain the same, but to have another WHERE in the same query line, but for finding the ones that do not have NULL in the row.


The following is the code I want to implement.


-> WHERE Address IS NULL <-


I have already tried the below codes.



SELECT *, COUNT(1) AS `items` FROM dbName WHERE user='$email' AND phone IS NOT NULL GROUP BY `lastname`,`firstname`,`address`

SELECT *, COUNT(1) AS `items` FROM dbName WHERE user='$email' AND phone IS NOT NULL, GROUP BY `lastname`,`firstname`,`address`

SELECT *, COUNT(1) AS `items` FROM dbName GROUP BY `lastname`,`firstname`,`address` WHERE user='$email' AND phone IS NOT NULL


This IS within a php file I am working on within a query as such.



$isql = $db->prepare("SELECT *, COUNT(1) AS `numbitems` FROM videos WHERE uploader='$email' GROUP BY `category`,`firstname`,`lastname`")


Which currently works just fine, but I will need the IS NOT NULL function implemented.


Any and all help and/or tips are very much appreciated. If you require any more information, I will be more the happy to edit as soon as I possibly can. Thank you all.





Aucun commentaire:

Enregistrer un commentaire