views:

43

answers:

1

Hello i have table

sitizen(id_citizen,name,sname,age,id_city)

i try do query

select a.name_city,b.name,b.age from city a,citizen b where a.id_city = b.id_city and
b.name = 'DAVE' order by b.age desc

expect result like this

 - NY | DAVE | 65

 - NY | DAVE | 12

 - NY | DAVE | 3

but see result what i can't anderstand

 - NY | DAVE | 65

 - NY | DAVE | 3

 - NY | DAVE | 12

if i change desc on ask in query result not better

 - NY | DAVE | 12

 - NY | DAVE | 3

 - NY | DAVE | 65

how it can be ?the age is(int)

another names with this query work fine but not all

CREATE TABLE tz.citizen(
  id_citizen INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  sname VARCHAR(255) NOT NULL,
  age VARCHAR(255) NOT NULL,
  id_sity INT(11) NOT NULL,
  PRIMARY KEY (id_citizen)
)
ENGINE = INNODB
AUTO_INCREMENT = 5
AVG_ROW_LENGTH = 4096
CHARACTER SET latin1

COLLATE latin1_swedish_ci;

+2  A: 

It appears that an alphanumeric sorting is being used. This could be because the age field is actually a string type such as varchar and not an integral type as you have stated.

Run SHOW CREATE TABLE citizen to double-check the type and change it to an integral type if necessary.

Mark Byers
i see it varchar )Thanks
alexandr