I’m reading though this db query, and i’m not sure that I need the l. before each selection..
What does l. as in l.id or l.node_id stand for? Do I need it? If not, what would I use it for?
SELECT
l.id, l.node_id,
l.name, l.phone, l.email
FROM
leads l
WHERE
l.active = 1
AND agent_id = '.$user->id.'
GROUP BY l.id
It’s an alias, standing for the table.
FROM leads lmeans “from the tableleads, which will be referred to aslelsewhere in this query”. To write the query without an alias, you could write:But since there’s only one table in this query, you don’t need to use any prefix at all; something like this is perfectly fine:
Normally a prefix like this (either
leads.orl.) is used when there’s some ambiguity that the query-writer wants to address — either to avoid confusing the database engine, or to avoid confusing a human reading the query, or both — but some people are in the habit of always using these prefixes, both for explicitness and so they never risk introducing an ambiguity.