[SOLVED] Correct syntax for sql query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

[SOLVED] Correct syntax for sql query

Post by Jim_Bo »

Hi,

Whats to correct way to do the following:

Code: Select all

$sql = "SELECT * FROM users WHERE status = 'Active' AND 'Barely Active' AND 'Inactive' AND user_level = '2' AND '3'";
Thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to Database.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mind explaining the logic you are going after?
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

Yer I have 2 fields that hold predefined info that I need to filter down ..

ie:

field "status" which holds one of the following values ...

Active, Barely Active, Inactive, Resigned

Field "user_level" which holds one of the following values ...

1, 2, 3, 4, 5

I am trying to display users that match the following ...

Active, Barely Active, Inactive

2,3,4,5

Not displaying any users matching "user_level" 1 or "status" Resigned

Also counting the records that match the above values ..

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT * FROM `users` WHERE `status` IN ('Active','Barely Active', 'Inactive) AND `user_level` IN ('2','3')
I believe.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi feyd,

That works great ..

Thanks ..


Jim_bo
Post Reply