我正在尝试 ORDER BY 日期类型字段名称为 dDate (格式示例为2008-12-26
),但它不起作用,请有人告诉我我做错了什么。
$listsql = "SELECT contact.id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname,
dDate, line1, line2, city, state, zip, phone1, phone2, country, whoAdded
FROM ". TABLE_CONTACT ." AS contact
LEFT JOIN ". TABLE_ADDRESS. " AS address ON contact.id=address.id AND contact.primaryAddType=address.type
LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id AND contact.primaryAddType=email.type
WHERE contact.hidden != 1
ORDER BY email.dDate DESC";
它没有给出任何错误或任何它只是没有排列日期我希望它有日期排列 DESC 或 ASC 无关紧要,例如:
2008-12-26
2008-12-27
2008-12-28
或者
2008-12-28
2008-12-27
2008-12-26
我得到这样的东西
2012-11-16
2012-11-30
2012-11-26
2012-11-30
SQL 输出是:
mysql> show create table address_email;
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| Table | Create Table
|
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
| address_email | CREATE TABLE `address_email` (
`id` int(11) NOT NULL DEFAULT '0',
`dDate` date DEFAULT NULL,
`type` varchar(100) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+---------------+---------------------------------------------------------------
--------------------------------------------------------------------------------
-------------------------+
1 row in set (0.00 sec)
非常感谢你的帮助。。