Abbreviations in mysql select, what do they mean?

I have a problem to understand what is going on in this request:

$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 fieldnamesthese, these are not tablenames, but I suspect reductions in some connections, but I have never seen them before.

I can rewrite my own request to complete the task, but I like to know what this means, so I can solve the problem myself (sending mail twice)

Thanks in advance for your help!

+4
source share
3 answers

See FROM lp_relations r, lp_mailings_relations m .
After the names of the actual tables, you will find the new name used to make SELECT shorter and easier to read.
So, the lp_relations table becomes r, and the lp_mailings_relations table becomes m!

You can 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 
+10
source

r stands for lp_relations table, and m stands for lp_mailings_relations table. Aliases help you combine by separating the fields. For example, if you have a user table that has the same field name as the product table, aliases help separate this (not ambiguous).

+1
source

They are the "aliases" of table names. Notice how in your query you say " from lp_relations r... "? The "R" at the end of this alias is now bound to lp_relations. Thus, you can refer to lp_relations in this query with only "r." This is a shorthand to make things more readable.

+1
source

All Articles