我从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)的降序说。
我该怎么办?请告诉我。感谢名单..
答案 0 :(得分:1)
SELECT * FROM table_list ORDER BY col_name DESC LIMIT 1;
答案 1 :(得分: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");
答案 2 :(得分:0)
在limit 1
order by your_column_name desc
答案 3 :(得分: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** ");
答案 4 :(得分: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来自party_details a,case_decision b,assign_advocate c其中 MONTHNAME(b.date)='$ month'和YEAR(b.date)='$ year'和a.partyid = b.party_id和 a.partyid = c.party_id和c.status ='1'顺序由col_name desc limit 1“);
答案 5 :(得分: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