i have a problem to understand what happens in this query:
$db->select("select r.id, m.mailing_id, r.email,
m.done from lp_relations r, lp_mailings_relations m
where m.relation_id=r.id and m.mailing_id=? order by r.name",
$rs[$i]["id"]
its about the letters r
. and m
. before the fieldnamesthese, these aren't tablenames, but i suspect abbreviations of some kind of joins, but i have never seen them before this way.
I can rewrite my own query to get the job done, but i lik开发者_高级运维e to know what this means, so i can tackle the problem itself (mailing sent twice)
Thanks in advance for any help!
Look at
FROM lp_relations r, lp_mailings_relations m
.
After real table names you find a new name, used to make SELECT part shorter and easy to read.
So table lp_relations becomes r and table lp_mailings_relations becomes m!
You could write:
SELECT r.id, r.email, m.mailing_id, m.done
FROM lp_relations r INNER JOIN lp_mailings_relations m
ON m.relation_id=r.id
WHERE m.mailing_id=?
ORDER BY r.name
They're "aliases" of table names. Note how in your query you say "from lp_relations r...
"? The "r" at the end of that is aliased to lp_relations now. So you can refer to lp_relations in that query with just "r.". It's a shorthand to make things a bit more readable.
r stands for the lp_relations table and m stands for the lp_mailings_relations table. The aliases help you do joins by separating out the fields. For instance if you had a users table that had the same field name found in a products table, the aliases help separate that out (non-ambiguous).
精彩评论