Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HAVING in Select statment

Status
Not open for further replies.

beyondflash

Programmer
Joined
Sep 4, 2005
Messages
8
Location
US
I have multiple items that I don't want selected in my select statement...I can get ONE to work here is a sample:

$sql = "SELECT * FROM login
WHERE (Email = '$email') HAVING Crsnum != 1 ORDER BY ID DESC";

This will not select any Crsnum that =1...
The problem I am having is I have multiple crsnum's that cannot be selected example:

1,4,9,17,19

How do I create the SELECT statement to omit those index numbers from being selected??

Thanks.
 
may be you need to use IN key word...

WHERE Crsnum IN (1,4,9,17,19)

-DNG
 
Or even:
[tt]
WHERE crsnum NOT IN (1,4,9,17,19)
[/tt]
 
when I add a second WHERE I get an sql error msg

$sql = "SELECT * FROM login
WHERE (Email = '$email')
WHERE crsnum NOT IN (1,4,9,17,19)
ORDER BY ID DESC";
 
You must use:
[tt]
WHERE email='$email' AND crsnum ...
[/tt]
 
should be like this...

WHERE CONDITION1 AND CONDITION2

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top