1

我正在尝试 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)

非常感谢你的帮助。。

4

1 回答 1

0

我变了:

LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id AND contact.primaryAddType=email.type

到:

LEFT JOIN ". TABLE_EMAIL ." AS email ON contact.id=email.id

我想在使用两个 LEFT JOIN 时永远不会有两个 primaryAddType

所以现在一切都很好!!!!谢谢大家!!:)

于 2012-11-29T22:22:15.150 回答