I have two tables which i make more quickly, now i had gathered a little more data and should be changed. The first would like to add information from second so i can delete that username.
INSERT INTO players
(id, username) VALUES (
(SELECT id FROM userstats) AS id,
(SELECT username FROM userstats) AS username)
In the second to combine the same id's and order by last entry also show me last entered data for that id, now it show me first data.
SELECT us.*, COUNT(us.id) as total, p.username
FROM userstats AS us
LEFT JOIN players AS p
ON p.id = us.id
GROUP BY us.id
ORDER BY
CASE
WHEN us.spyed_at IS NULL
THEN 1
ELSE 2
END ,
us.spyed_at DESC
Im also comfused what is better used if i want show username if its id exists if not show id. SQL case or php if?
Thanks!