If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Find values that are not in sequence

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-31-10, 04:50
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Question Find values that are not in sequence

Hello,

How to find values that are not in sequence ?

A
B
C
D
Z
E
F
G

or something like this:

1
2
3
8
4
5
6

Each of the highlighted values is not in the proper sequence, how to find those ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 03-31-10, 06:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
like i mentioned on devshed, you have to give more information

please show the actual query that produces these results

as you know, the rows of a table do not have an inherent order, and especially not a table consisting of only one column
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-31-10, 08:34
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Quote:
Originally Posted by r937 View Post
like i mentioned on devshed, you have to give more information

please show the actual query that produces these results

as you know, the rows of a table do not have an inherent order, and especially not a table consisting of only one column
Hello r937,

Actually I don't have any working query, i was wondering that if its possible through MySQL ?
Thanks for ur reply.
Reply With Quote
  #4 (permalink)  
Old 03-31-10, 10:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
It may be possible, depending on the problem. We may be able to answer your question once you provide more detail, but as you've asked the question so far the answer is "maybe".

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #5 (permalink)  
Old 03-31-10, 11:12
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
The bigger question is why would the sequence matter, except when you display
Dave
Reply With Quote
  #6 (permalink)  
Old 04-01-10, 05:10
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Hello,

Please refer the example:

Table

Andy Xyz
Bruce Xyz
Collinwood Xyz
Dragon Xyz
Zypher Xyz
Elli Xyz
Frank Xyz

As u can see, the name Zypher is not in alphabetical series.
So, can it be sorted out by using MySql query ?

Thanks
Reply With Quote
  #7 (permalink)  
Old 04-01-10, 05:17
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
is all you are asking is can you get rows ordered into a specific order?
if so the answer is yes... place on ORDER BY clause at the end of the select statement

if you have another sequence and you want to finds rows out of sequence then thats a different and much more complex task
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #8 (permalink)  
Old 04-01-10, 05:27
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Quote:
Originally Posted by healdem View Post
is all you are asking is can you get rows ordered into a specific order?
if so the answer is yes... place on ORDER BY clause at the end of the select statement

if you have another sequence and you want to finds rows out of sequence then thats a different and much more complex task
Hii Healdem.
Thanks for replying

Yaa, I am trying to finds rows which are out of sequence.
Reply With Quote
  #9 (permalink)  
Old 04-01-10, 06:48
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
like i said, rows will be placed in table according to space and clustering, what difference does it make how they are put into table? and why would you need to find them? Allow the database to store the data according to its needs and you can query/order the data according to your needs.
Dave
Reply With Quote
  #10 (permalink)  
Old 04-01-10, 07:00
andy982183 andy982183 is offline
Registered User
 
Join Date: Mar 2010
Posts: 18
Quote:
Originally Posted by dav1mo View Post
like i said, rows will be placed in table according to space and clustering, what difference does it make how they are put into table? and why would you need to find them? Allow the database to store the data according to its needs and you can query/order the data according to your needs.
Dave
Hii Dave,

The records which are alphabetically arranged are like tel. directory structure for different cities.

So it cannot be sorted in Asc/Dsc order by name, because all the cities will get merged.

keeping the record structure intact, i need to find the "out-of-sequence" records.

Thanks.

Last edited by andy982183; 04-01-10 at 07:10.
Reply With Quote
  #11 (permalink)  
Old 04-01-10, 07:01
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by andy982183 View Post
Yaa, I am trying to finds rows which are out of sequence.
good news!!! your quest is over!!!

rows in a table have no sequence (i told you this days ago)

you may now move on to your next problem
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 04-01-10, 09:39
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
can you identisy how a row will be out of sequence
and what cause that out of sequence condition, as others have said the way data is stored in a database is out of your control and you cannot rely on the db storing data in a specific sequence.

thats why the designers of SQL implemented the ORDER BY clause.
read da manuel as to what sort of (pardon the deliberate pun) order you want yoru rows to come in.

unless you have a really really flaky design and obtuse data source then ORDER BY should be able to do what you want

a footnote, as others have said, this forum isn't really for learning SQL from the roots, its about helping. if you are an absolute beginner then there are plenty of other sites such as w3schools. heck theres even some good books on SQL... You could always buy a copy of Rudy's (R937) book simply SQL.. in all good signatures on this forum.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #13 (permalink)  
Old 04-02-10, 00:11
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
Quote:
The records which are alphabetically arranged are like tel. directory structure for different cities.

So it cannot be sorted in Asc/Dsc order by name, because all the cities will get merged.
MORE GOOD NEWS .... you can have more than one field in your ORDER BY clause so use
ORDER BY
city,
last name
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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