~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/functions/logical.rst

  • Committer: Lee Bieber
  • Date: 2011-02-23 23:31:15 UTC
  • mfrom: (2194.5.7 trunk-bug-723653)
  • mto: This revision was merged to the branch mainline in revision 2197.
  • Revision ID: kalebral@gmail.com-20110223233115-oke1fnvjuu6ujkya
Merge Andrew - 723653: Docs day first pass fixes 

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
* evaluates to 0 if one or more operands are 0 
29
29
* otherwise returns NULL 
30
30
 
31
 
::
 
31
.. code-block:: mysql
32
32
 
33
33
        SELECT 1 && 1;
34
34
                -> 1
41
41
        SELECT NULL && 0;
42
42
                -> 0
43
43
 
44
 
AND can be used to select rows that satisfy all the conditions given in a statement. For Example, to find the names of the students between the age 20 to 25 years, the query would be like: ::
 
44
AND can be used to select rows that satisfy all the conditions given in a statement. For Example, to find the names of the students between the age 20 to 25 years, the query would be like:
 
45
 
 
46
.. code-block:: mysql
45
47
 
46
48
        SELECT first_name, last_name, age
47
49
        FROM user_details
72
74
* returns 1 with a NULL operand if the other operand is nonzero, and retunes NULL otherwise
73
75
* returns NULL if both operands are NULL
74
76
 
75
 
::
 
77
.. code-block:: mysql
76
78
 
77
79
        SELECT 1 || 1;
78
80
                -> 1
87
89
 
88
90
In other words, OR is used to select rows that satisfy at least one of the given conditions.
89
91
 
90
 
For example, the following query could be used to find the user_id for people that live in either California or Texas: ::
 
92
For example, the following query could be used to find the user_id for people that live in either California or Texas:
 
93
 
 
94
.. code-block:: mysql
91
95
 
92
96
        SELECT user_id, state
93
97
        FROM user_location
115
119
* evaluates to 1 for non-NULL operands (if an odd number of operands is nonzero)
116
120
* otherwise 0 is returned
117
121
 
118
 
::
 
122
.. code-block:: mysql
119
123
 
120
124
        SELECT 1 XOR NULL;
121
125
                -> NULL
140
144
* evaluates to 0 if the operand is nonzero
141
145
* NOT NULL returns NULL
142
146
 
143
 
::
 
147
.. code-block:: mysql
144
148
 
145
149
        SELECT NOT 10;
146
150
                -> 0
155
159
 
156
160
If you want to find rows that do not satisfy a condition, you can use the logical operator, NOT. NOT results in the reverse of a condition. That is, if a condition is satisfied, then the row is not returned.
157
161
 
158
 
For example: If you want to find out the user_id for people who do not practice medicine as their profession, the query would be like: ::
 
162
For example: If you want to find out the user_id for people who do not practice medicine as their profession, the query would be like:
 
163
 
 
164
.. code-block:: mysql
159
165
 
160
166
        SELECT user_id, title, occupation
161
167
        FROM user_occupations
179
185
LESS THAN
180
186
----------
181
187
 
182
 
Less than: ::
 
188
Less than:
 
189
 
 
190
.. code-block:: mysql
183
191
 
184
192
        SELECT 2 < 2;
185
193
                -> 0
190
198
GREATER THAN
191
199
-------------
192
200
 
193
 
Greater than: ::
 
201
Greater than:
 
202
 
 
203
.. code-block:: mysql
194
204
 
195
205
        SELECT 2 > 2;
196
206
                -> 0
200
210
LESS THAN OR EQUAL
201
211
-------------------
202
212
 
203
 
Less than or equal: ::
 
213
Less than or equal:
 
214
 
 
215
.. code-block:: mysql
204
216
 
205
217
        SELECT 0.1 <= 2;
206
218
                -> 1
211
223
GREATER THAN OR EQUAL
212
224
----------------------
213
225
 
214
 
Greater than or equal: ::
 
226
Greater than or equal:
 
227
 
 
228
.. code-block:: mysql
215
229
 
216
230
        SELECT 2 >= 2;
217
231
                -> 1
221
235
EQUAL
222
236
-----
223
237
 
224
 
Equal: ::
 
238
Equal:
 
239
 
 
240
.. code-block:: mysql
225
241
 
226
242
        SELECT 1 = 0;
227
243
                -> 0
240
256
NOT EQUAL
241
257
----------
242
258
 
243
 
Not equal: ::
 
259
Not equal:
 
260
 
 
261
.. code-block:: mysql
244
262
 
245
263
        SELECT '.01' <> '0.01';
246
264
                -> 1