0

我从 3 个不同的表中选择一些值,例如,

$result=mysql_query("select a.party_name, a.app_date, a.receive_date, a.case_type, c.order_date from party_details a, case_decision b, assign_advocate c where MONTHNAME(b.date)='$month' and YEAR(b.date)='$year' and a.partyid=b.party_id and a.partyid=c.party_id and c.status='1'");

但我只想从底部选择 1 个值,或者按表 c 的降序排列(case_decision)。

我怎样才能做到这一点。请告诉我。谢谢..

4

6 回答 6

1
 SELECT * FROM table_list ORDER BY col_name DESC LIMIT 1; 
于 2012-10-15T07:10:18.250 回答
0

您必须<column>在下面的查询中替换为您希望订单所基于的列的引用。

select a.party_name, a.app_date, a.receive_date, a.case_type, c.order_date
from party_details a, case_decision b, assign_advocate c
where MONTHNAME(b.date)='$month' and YEAR(b.date)='$year'
and a.partyid=b.party_id and a.partyid=c.party_id and c.status='1'
order by <column> desc
limit 1
于 2012-10-15T07:16:29.887 回答
0

'order by' 将根据列 'desc' 降序排序

$result=mysql_query("select a.party_name, a.app_date, a.receive_date, a.case_type, c.order_date from party_details a, case_decision b, assign_advocate c where MONTHNAME(b.date)='$month' and YEAR(b.date)='$year' and a.partyid=b.party_id and a.partyid=c.party_id and c.status='1' order by a.party_name desc");

于 2012-10-15T07:08:51.337 回答
0

limit 1之后使用order by your_column_name desc

于 2012-10-15T07:09:35.193 回答
0

使用orderby子句

示例(语法):

SELECT * FROM YOUR_TABLE_NAME ORDER BY YOUR_COL_NAME DESC LIMIT 1; 

在您的情况下,您应该这样做:

$result=mysql_query("select a.party_name, a.app_date, a.receive_date, a.case_type, 
c.order_date from party_details a, case_decision b, assign_advocate c where 
MONTHNAME(b.date)='$month' and YEAR(b.date)='$year' and a.partyid=b.party_id and 
a.partyid=c.party_id and c.status='1' **ORDER BY YOUR_COLOUM_NAME  DESC LIMIT 1** ");
于 2012-10-15T07:11:15.300 回答
0
Please replce column name as per table design below statement :

$result=mysql_query("select a.party_name, a.app_date, a.receive_date, a.case_type, c.order_date from party_details a, case_decision b, assign_advocate c where MONTHNAME(b.date)='$month' and YEAR( b.date)='$year' and a.partyid=b.party_id and a.partyid=c.party_id and c.status='1' order by col_name desc limit 1");

于 2012-10-15T07:11:38.060 回答