473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Range query

This query returns only those starting with A and B. Why?
SELECT name FROM mytable WHERE name BETWEEN 'A' AND 'C'
Jul 20 '05 #1
3 1461
On 18 Aug 2004 07:19:13 -0700, Rathtap wrote:
This query returns only those starting with A and B. Why?
SELECT name FROM mytable WHERE name BETWEEN 'A' AND 'C'


Hi Rathap,

Because the name 'Chris' is considered to be greater than 'C'. If the
first character is equal, comparison looks at the second, etc; for this
purpose, the shorter name is padded with spaces. So the comparison of
'Chris' to 'C' in detail: 'C" gets padded to 'C '; the first characters
(both 'C') are equal; 'h' is compared to ' ' and is greater.

Remember that myname BETWEEN 'A' AND 'C' is shorthand for myname >= 'A'
AND myname <= 'C', so all names beginning with A or B will be selected, as
well as names exactly equal to 'C'.

To get all names beginnen with A, B and C, use BETWEEN 'A' AND 'CZZZZZZZ'
(and check how numbers and special characters sort in your collation), use
myname >= 'A' and myname < 'D', or use myname LIKE '[ABC]%'.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
"Rathtap" <am****@yahoo.com> wrote in message
news:b2**************************@posting.google.c om...
This query returns only those starting with A and B. Why?
SELECT name FROM mytable WHERE name BETWEEN 'A' AND 'C'


The first value is inclusive while the second value is exclusive in a
BETWEEN expression.

You could try :
WHERE name >= 'A'
AND name <= 'C'

Or :
BETWEEN 'A' AND 'D'

Depending on what you were trying to achieve.
Jul 20 '05 #3
On Wed, 18 Aug 2004 15:38:13 +0000 (UTC), Rowland wrote:
"Rathtap" <am****@yahoo.com> wrote in message
news:b2**************************@posting.google.c om...
This query returns only those starting with A and B. Why?
SELECT name FROM mytable WHERE name BETWEEN 'A' AND 'C'


The first value is inclusive while the second value is exclusive in a
BETWEEN expression.


This is wrong. The second value is inclusive; but names that *start* with
C are not included because they are not *between* A and C.

This means that if there is a plain value 'C' in your table, it will be
included, but 'CALLIE' will not, because 'CALLIE' > 'C'

(Hugo Kornelis already explained this, but I wanted to follow up this
incorrect impression.)

You can use BETWEEN 'A' AND 'CZZZZZZZ', or LIKE '[ABC]%' as Hugo suggested,
or you can use WHERE LEFT(myname,1) BETWEEN 'A' AND 'C'. I suspect that the
first alternative is most efficient.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
I am a relatively new user on Oracle 9.2.0.1 and I am having trouble performance tuning this production database. I am running a large query that joins two tables, document(3 mil) and entity(9...
3
by: aroy | last post by:
Hi, Need help in optimizing a query in SQL Server. Following is the problem statement. There are two tables; 1st table (t1) has a KEY ( char(8) ) column, with a clustered index. this is not...
4
by: Jorey Bump | last post by:
I can retrieve today's date: mysql> SELECT CURDATE() AS begin; +------------+ | begin | +------------+ | 2005-06-01 | +------------+ 1 row in set (0.00 sec)
3
by: manning_news | last post by:
Using A2K. I've been asked to modify a report currently requiring only one date parameter to now accept a date range. The main report has 2 subreports and is not bound to a table or query. The...
4
by: amy | last post by:
Hi to Everyone: I need big help on how to query the Age range. Age field is text data type, Age are from 0 wk, 1 wk, 2wk.....up to 15 wk. Try to set up query in Query desing mode with criteria is...
1
by: isetea | last post by:
Hi, I want to create a from where user can select from a date range / type in a date range to get only data from an underlying query within this range. This should overwrite the existing criteria...
4
by: Tess2819 | last post by:
Hi Everyone, This is my first topic so I hope you can help. I have searched but can't seem to find what I am looking for, so here it is. I want to create a query using design view in...
2
by: sixdeuce62 | last post by:
Hello, I am trying to create a query that will prompt me to enter the parameter value if beginning date and ending date. I have created everything I need in the query, but I have to manually go...
1
by: flumpuk | last post by:
Hi My job currently requires me to enter data from 300+ forms a month. The system which we used in Excel was slow , and theprevious guy had three workbooks for this job . I have created...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.