php - Select records from one table and sort the result using a column from another table -


i'm working on payroll system crm located @ work , i'm trying save having store redundant data on period of years stack up.

i tried relate "how value mysql table ordered table?" had no luck.

i have users table

=========================================== # id | username | first_name | last_name  # =========================================== # 1  |   joe    |    joe     |    blow    # =========================================== 

i have timesheets table stores data of each individual session sake of keeping short have condensed little in question , misses full date/time in start , finish.

============================================ # id | username |    start   |   finish    # ============================================ # 1  |   joe    |   00:00    |    23:59    # ============================================ 

what want achieve order results timesheets table last_name column in users table username derived timesheets table.

what trying attempt here:

select * `timesheets` `start` >= '{$monday}' , `finish` <= '{$sunday}' order (`users`.`last_name` `username` = `timesheets`.`username`)  asc 

mysql not niche, query provide desired result?

you'd have use join , order by, this:

select ts.* timesheets ts join users on ts.username = users.username order users.last_name 

you may add where clause required before order by.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -