Some days ago I asked here for a solution to retrieve a query which gets values from two diferent tables. The question was asked quite fast, thanks to this awesome community here... But continuing: I used the query and it worked perfectly, but I don't understand it. The query is following:
SELECT e.*, u.Username
FROM Entries AS e
LEFT JOIN Users AS u ON u.ID = e.User
WHERE e.Category = 'SomeCategory'
LIMIT 0, 10
Can anyone explain what each "step" of the query does? "WHERE","LIMIT","SELECT" and "FROM" I know, but the others get quite complicated for me.
Thanks
EDIT: LIMIT 10,0
changed to LIMIT 0,10
. I written it the wrong way... Sorry about that.
SELECT e.*, u.Username
FROM Entries AS e
LEFT JOIN Users AS u ON u.ID = e.User
WHERE e.Category = 'SomeCategory'
LIMIT 10, 0; -- are you sure about it???
How it works:
Entries
table and "rename" it to e
(add alias)Users
table and "rename" it to u
ID
column from Entries
and User
from Users
(for non matched rows from Users set NULL
)Category
column is equal 'SomeCategory'
Entries
and Username
column from Users
Warning
Without explicit ORDER BY
you can get different resultsets between executions. Why you want to return empty resultset LIMIT offset, row_count
?
EDIT:
After your edit 5. should be Skip first 0 rows and get 10 rows
LIMIT 0, 10
is the same as LIMIT 10