Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

merging two mysql sentence

Dear Experts,

I use PHP 7.2 and mySQL version 5.6

with below SQL I got the first entry of my users which is entered yesterday, however I also need to get the last entry of the same users which is entered yesterday,
how can I do that?
I want to show the first and the last entry of my users and their entrance time on the same table.

this sql works perfectly fine to bring the first enterance,

$sql = "SELECT uid,tarih FROM takip WHERE tarih >= '$raportarihi' group by uid ORDER BY `takip`.`tarih` DESC";

Open in new window


this sql works perfectly fine to bring the last enterance,

$sql = "SELECT uid,max(tarih) as tarih FROM takip WHERE tarih >= '$raportarihi' group by uid ORDER BY max(tarih) asc";

Open in new window


how can merge these two sql statements to get the data inside only one table?

thank you
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

ohh, thank you so much, why didn't I think of that?
thank you
Avatar of skullnobrains
skullnobrains

be my guest ;)
we tend to forget such features because we usually expect the fields selected to be consistent ( pulled from the same row ) which is not the case with aggregation and group by clauses.
happy coding to you !