dbTalk Databases Forums  

"between A and B" with another condition?

mailing.database.mysql mailing.database.mysql


Discuss "between A and B" with another condition? in the mailing.database.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lingua2001
 
Posts: n/a

Default "between A and B" with another condition? - 07-22-2003 , 10:41 AM






Hi there,

How can I extract values for "members whose level is below '3', and
their names are between the alphabets 'a' and 'b' "?
For example, one of the results should be 'Alex', whose level is '1'.
Or 'Bob', whose level is '2'. But not Charlie, or Tom...etc.

I tried a query like

SELECT uid FROM members WHERE level > '1' AND name between 'a' and 'b',

but it does not work....

Could anyone give me a good solution?

Thanks for your help in advance.

Lingua

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Viorel Dragomir
 
Posts: n/a

Default Re: "between A and B" with another condition? - 07-22-2003 , 10:50 AM







----- Original Message -----
From: "Lingua2001" <lingua2001 (AT) hotmail (DOT) com>
To: <mysql (AT) lists (DOT) mysql.com>
Sent: Tuesday, July 22, 2003 10:37 AM
Subject: "between A and B" with another condition?


Quote:
Hi there,

How can I extract values for "members whose level is below '3', and
their names are between the alphabets 'a' and 'b' "?
For example, one of the results should be 'Alex', whose level is '1'.
Or 'Bob', whose level is '2'. But not Charlie, or Tom...etc.

I tried a query like

SELECT uid FROM members WHERE level > '1' AND name between 'a' and 'b',
if you want the level below 3 then set the where clause with level < 3
i guess this is your query:
SELECT uid FROM members WHERE level < 3 AND name between 'a' and 'b',

i recommend that your level is defined as a number, otherwise you must make
a cast to number (int)
because '3'>'13'

/v

Quote:
but it does not work....

Could anyone give me a good solution?

Thanks for your help in advance.

Lingua

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=b...) vio (DOT) ro


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Bruce Feist
 
Posts: n/a

Default Re: "between A and B" with another condition? - 07-22-2003 , 11:27 AM



Lingua2001 wrote:

Quote:
How can I extract values for "members whose level is below '3', and
their names are between the alphabets 'a' and 'b' "?
For example, one of the results should be 'Alex', whose level is '1'.
Or 'Bob', whose level is '2'. But not Charlie, or Tom...etc.

I tried a query like

SELECT uid FROM members WHERE level > '1' AND name between 'a' and 'b',

but it does not work....

There's a problem with the condition on level, as George and Peter have
noted, and also a more subtle one on name. Try "name between 'a' and
'bzzzzzzzzz' or something of the sort instead; 'Bob' > 'b' and just
specifying the first letter won't work. Or, if you're worried about
trailing z's or other high characters, try "name >= 'a' and name < 'c'".

Bruce Feist



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Lingua2001
 
Posts: n/a

Default Re: "between A and B" with another condition? - 07-22-2003 , 03:51 PM



Yes...

Does it work?

----- Original Message -----
From: "Bob Ramsey" <robert-ramsey (AT) uiowa (DOT) edu>
To: "Lingua2001" <lingua2001 (AT) hotmail (DOT) com>; <mysql (AT) lists (DOT) mysql.com>
Sent: Tuesday, July 22, 2003 10:57 AM
Subject: Re: "between A and B" with another condition?


Quote:
Like this?

mysql> select * from t2;
+---------+--------+
| name | number |
+---------+--------+
| bob | 3 |
| bob | 2 |
| bob | 1 |
| al | 1 |
| al | 2 |
| al | 3 |
| al | 4 |
| adam | 4 |
| adam | 3 |
| adam | 2 |
| charlie | 2 |
+---------+--------+
11 rows in set (0.00 sec)

mysql> select * from t2 where (number <3) and (name between 'a' and 'c');
+------+--------+
| name | number |
+------+--------+
| bob | 2 |
| bob | 1 |
| al | 1 |
| al | 2 |
| adam | 2 |
+------+--------+
5 rows in set (0.00 sec)

Is that what you mean?




================================================== ====================
Bob Ramsey Applications Development & Support II
ph: 1(319)335-9956 216 Boyd Law Building
fax: 1(319)335-9019 University of Iowa College of Law
mailto:robert-ramsey (AT) uiowa (DOT) edu Iowa City, IA 52242-1113
For Hardware and Software questions, call 5-9124
================================================== ====================


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.