这是sql表tbl_message由user_id记录的不同记录,但是最后一个id显示了mins DESC记录表单id

时间:2017-02-03 11:43:40

标签: php mysql sql-server

这是sql表tbl_message由user_id记录的不同记录但是最后一个id显示的是分钟DESC记录表单id

array(
    0=>50,
    1>70
);

for($get_whol_price=0;$get_whol_price<count($get_wholeUnits);$get_whol_price++){
    if(350 >= $get_wholeUnits[$get_whol_price]){
        $wholesale_price_Set = $get_wholeUnits[$get_whol_price];
        $gross_price = 350 * $get_wholePrices[$get_whol_price];
    }
}

2 个答案:

答案 0 :(得分:1)

如果您需要最新的insterted user_id而不重复,那么您应该使用此查询

SELECT t2.id,t2.message,t2.user_id FROM (SELECT DISTINCT user_id,message,id FROM msg ORDER BY user_id)t2 ,msg t1 GROUP BY user_id;

答案 1 :(得分:0)

这就是你在寻找什么

SELECT 
    `t1`.*
FROM 
    `messages` `t1`
        INNER JOIN
            (
                SELECT
                    MAX(`id`) as `latest`,
                    `user_id`
                FROM
                    `messages`
                GROUP BY
                    `user_id`) `t2`
        ON
            `t1`.`user_id` = `t2`.`user_id` AND
            `t1`.`id` = `t2`.`latest`