PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > order by not working
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
order by not working

Réponse
 
LinkBack Outils de la discussion
Vieux 30/09/2007, 20h12   #1
bill
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut order by not working

I give this sql request:
$sql = "SELECT * FROM incoming_email order by 'status','serial' limit
1 ";

where status is a 5 char varchar and serial is a mediumint and the
primary key.

There is an index
STATUS with no cardinality and fields: status, serial

The row returned is the one with the lower serial, but a higher status

eg serial status
269 held
is returned instead of
270 (status is blank)

How should the selection be written ?

bill

  Réponse avec citation
Vieux 30/09/2007, 20h35   #2
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: order by not working

bill wrote:
> I give this sql request:
> $sql = "SELECT * FROM incoming_email order by 'status','serial' limit
> 1 ";
>
> where status is a 5 char varchar and serial is a mediumint and the
> primary key.
>
> There is an index
> STATUS with no cardinality and fields: status, serial
>
> The row returned is the one with the lower serial, but a higher status
>
> eg serial status
> 269 held
> is returned instead of
> 270 (status is blank)
>
> How should the selection be written ?
>
> bill


Is status blank or is it NULL?


  Réponse avec citation
Vieux 30/09/2007, 20h42   #3
bill
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: order by not working

On Sep 30, 3:35 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
> bill wrote:
> > I give this sql request:
> > $sql = "SELECT * FROM incoming_email order by 'status','serial' limit
> > 1 ";

>
> > where status is a 5 char varchar and serial is a mediumint and the
> > primary key.

>
> > There is an index
> > STATUS with no cardinality and fields: status, serial

>
> > The row returned is the one with the lower serial, but a higher status

>
> > eg serial status
> > 269 held
> > is returned instead of
> > 270 (status is blank)

>
> > How should the selection be written ?

>
> > bill

>
> Is status blank or is it NULL?



This is a good question. It is never defined in the insert, but the
structure says that the value may not be null but no default value is
given.
A quick select using phpMyAdmin for status = NULL returns no records
and one where status = '' (that is two single quotes) returns a
record, so I presume it is blank.

  Réponse avec citation
Vieux 30/09/2007, 21h04   #4
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: order by not working

bill wrote:
> On Sep 30, 3:35 pm, "Paul Lautman" <paul.laut...@btinternet.com>
> wrote:
>> bill wrote:
>>> I give this sql request:
>>> $sql = "SELECT * FROM incoming_email order by 'status','serial'
>>> limit 1 ";

>>
>>> where status is a 5 char varchar and serial is a mediumint and the
>>> primary key.

>>
>>> There is an index
>>> STATUS with no cardinality and fields: status, serial

>>
>>> The row returned is the one with the lower serial, but a higher
>>> status

>>
>>> eg serial status
>>> 269 held
>>> is returned instead of
>>> 270 (status is blank)

>>
>>> How should the selection be written ?

>>
>>> bill

>>
>> Is status blank or is it NULL?

>
>
> This is a good question. It is never defined in the insert, but the
> structure says that the value may not be null but no default value is
> given.
> A quick select using phpMyAdmin for status = NULL returns no records
> and one where status = '' (that is two single quotes) returns a
> record, so I presume it is blank.


Hold on a minute!

I just looked at your query again.

you are ordering by 'status', 'serial'

You have quoted the words and so are sorting by the strings "status" and
"serial"


  Réponse avec citation
Vieux 30/09/2007, 22h11   #5
Ana C. Dent
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: order by not working

bill <william@TechServSys.com> wrote in news:1191181320.074514.138890
@y42g2000hsy.googlegroups.com:

> On Sep 30, 3:35 pm, "Paul Lautman" <paul.laut...@btinternet.com>
> wrote:
>> bill wrote:
>> > I give this sql request:
>> > $sql = "SELECT * FROM incoming_email order by 'status','serial' limit
>> > 1 ";

>>
>> > where status is a 5 char varchar and serial is a mediumint and the
>> > primary key.

>>
>> > There is an index
>> > STATUS with no cardinality and fields: status, serial

>>
>> > The row returned is the one with the lower serial, but a higher status

>>
>> > eg serial status
>> > 269 held
>> > is returned instead of
>> > 270 (status is blank)

>>
>> > How should the selection be written ?

>>
>> > bill

>>
>> Is status blank or is it NULL?

>
>
> This is a good question. It is never defined in the insert, but the
> structure says that the value may not be null but no default value is
> given.
> A quick select using phpMyAdmin for status = NULL returns no records
> and one where status = '' (that is two single quotes) returns a
> record, so I presume it is blank.
>


> status = NULL

Nothing EVER "=" NULL

WHERE STATUS IS NULL might provide better/different results!
  Réponse avec citation
Vieux 01/10/2007, 14h46   #6
bill
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: order by not working

On Sep 30, 4:04 pm, "Paul Lautman" <paul.laut...@btinternet.com>
wrote:
> bill wrote:
> > On Sep 30, 3:35 pm, "Paul Lautman" <paul.laut...@btinternet.com>
> > wrote:
> >> bill wrote:
> >>> I give this sql request:
> >>> $sql = "SELECT * FROM incoming_email order by 'status','serial'
> >>> limit 1 ";

>
> >>> where status is a 5 char varchar and serial is a mediumint and the
> >>> primary key.

>
> >>> There is an index
> >>> STATUS with no cardinality and fields: status, serial

>
> >>> The row returned is the one with the lower serial, but a higher
> >>> status

>
> >>> eg serial status
> >>> 269 held
> >>> is returned instead of
> >>> 270 (status is blank)

>
> >>> How should the selection be written ?

>
> >>> bill

>
> >> Is status blank or is it NULL?

>
> > This is a good question. It is never defined in the insert, but the
> > structure says that the value may not be null but no default value is
> > given.
> > A quick select using phpMyAdmin for status = NULL returns no records
> > and one where status = '' (that is two single quotes) returns a
> > record, so I presume it is blank.

>
> Hold on a minute!
>
> I just looked at your query again.
>
> you are ordering by 'status', 'serial'
>
> You have quoted the words and so are sorting by the strings "status" and
> "serial"


That fixed it - thanks.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h20.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13176 seconds with 14 queries