How to check last row ref by column username using php and mysql? -


how check last row ref column username using php , mysql ?

this table

 _________________________________ |_id_|_____username_____|___val___| |  1 |      aaaa        |    3    | |  2 |      aaaa        |    4    | |  3 |      aaaa        |    5    | |  4 |      cccc        |    1    | |  5 |      cccc        |    3    | |  6 |      cccc        |    4    | |  7 |      cccc        |    7    | |  8 |      dddd        |    2    | |  9 |      dddd        |    4    | 

and code.

<?php include("connect.php"); $strsql = "select * table order id asc "; $objquery = mysql_query($strsql); while($objresult = mysql_fetch_array($objquery)) {     echo ["val"];     echo "<br>"; } ?> 

when test code. i'll echo

3 4 5 1 3 4 7 2 4 

but want echo username in last row this.

3 4 5 aaaaa 1 3 4 7 ccccc 2 4 ddddd 

how can ? thank you.

try this:

select t1.val,t2.username `test` t1 left join (select max(id) id,username `test` group username) t2 on t1.id=t2.id 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -