Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
AND won't work in SQL query
Old 03-13-2007, 08:19 PM AND won't work in SQL query
Skilled Talker

Posts: 99
Trades: 0
$query = "SELECT * FROM members WHERE disable AND resign > '0'";

why won't this work?? if I delete " and resign" it will work, but i need both to be true!
Arez20469 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2007, 09:18 PM Re: AND won't work in SQL query
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
What database engine? MySql probably?

So if you query "SELECT * FROM members WHERE disable" you get results??? Is disable a boolean field, and the SQL engine treats it as such, like in C?

Or is the query you want "SELECT * FROM members WHERE disable > '0' AND resign > '0'";
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 03-13-2007, 09:51 PM Re: AND won't work in SQL query
Skilled Talker

Posts: 99
Trades: 0
yes, I'm using MySQL

$query = "SELECT * FROM members WHERE disable > '0' AND resign > '0'"; didn't work! it doesn't display any members!! what is the right format?
Arez20469 is offline
Reply With Quote
View Public Profile
 
Old 03-13-2007, 10:47 PM Re: AND won't work in SQL query
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Didn't work and didn't return any data are two different issues; it's possible that, as far as the database knows, there are no members who meet your criteria. ( Canceled? )

Your second query is either the right format, or a lot closer; if disable and resign are character/text data types, then it's right. But if they're numeric, you don't need to put the zero in quotes.

In SQL, every clause in your WHERE ( or HAVING ) statement needs to be connected with and or or, like this:

Select *
From members
Where
disable > 0
And resign > 0

You could replace the and with an or, and get anybody who matches one, but not necessarily both, of the statements. You could get really complex and include both:

Where
(disable > 0 And resign > 0)
Or (flagged = 1)

In general you want to avoid huge, complex where clauses because they're more difficult to debug, and because using "or" in certain ways can force a table scan. But SQL allows this, so if you want to test two conditions in your query, you need to give the database a way to evaluate both fields.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 03-13-2007, 10:54 PM Re: AND won't work in SQL query
Skilled Talker

Posts: 99
Trades: 0
Changing it to OR instead of AND worked!!!!!!!!!
Arez20469 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2007, 06:55 PM Re: AND won't work in SQL query
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
For christ sake, learn a bit what SQL is, man...
http://sqlcourse.com/select.html
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-15-2007, 12:43 AM Re: AND won't work in SQL query
Extreme Talker

Posts: 189
Trades: 1
Quote:
Originally Posted by Arez20469 View Post
Changing it to OR instead of AND worked!!!!!!!!!
And there is a hug difference between the queries.
__________________

Please login or register to view this content. Registration is FREE
yellow1912 is offline
Reply With Quote
View Public Profile Visit yellow1912's homepage!
 
Old 03-15-2007, 03:19 PM Re: AND won't work in SQL query
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You do realize there's a huge difference between "and" and "or", right?
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to AND won't work in SQL query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.52033 seconds with 12 queries