[英]select only first row of an sub table join
am having the table goodsbooking_tbl 在桌子上有goodsbooking_tbl
what i need: need to select the rows inn main table with some ids, and also select only the first row of the main table id.. 我需要什么:需要选择具有一些ID的inn主表行,并且还仅选择主表ID的第一行。
was tryed this.. 尝试过这个..
SELECT a.idgoodsbooking_tbl, a.consignorId, a.ConsigneeId, date_format(a.bookingDate,'%d-%m-%Y') as GCdate,
a.GCNumber, a.frieghtTotal, a.paymentType,b.description FROM goodsbooking_tbl a
JOIN goodsbooking_subtbl b ON a.idgoodsbooking_tbl=b.idgoodsbooking_tbl WHERE a.idgoodsbooking_tbl in (1,2);
it returns 它返回
i need only the first row from the subtable ie. 我只需要子表的第一行,即。
1 3 1 01-01-2015 GC-15-01 15000.00 safdasf
2 2 1 01-01-2015 GC-15-02 350.00 sdafsaf
thanks in advance.. 提前致谢..
Because you want only one column, I think the easiest way might be a correlated subquery: 因为只需要一列,所以我认为最简单的方法可能是相关的子查询:
SELECT a.idgoodsbooking_tbl, a.consignorId, a.ConsigneeId,
date_format(a.bookingDate,'%d-%m-%Y') as GCdate,
a.GCNumber, a.frieghtTotal, a.paymentType,
(SELECT b.description
FROM goodsbooking_subtbl b
WHERE a.idgoodsbooking_tbl = b.idgoodsbooking_tbl
ORDER BY idgoodbooking_subtbl DESC
LIMIT 1
) as description
FROM goodsbooking_tbl a
WHERE a.idgoodsbooking_tbl in (1,2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.