Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

abbreviations in mysql select, what do they mean?

Tags:

select

mysql

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 like to know what this means, so i can tackle the problem itself (mailing sent twice)

Thanks in advance for any help!

like image 285
Terradon Avatar asked Dec 09 '22 05:12

Terradon


1 Answers

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
like image 92
Marco Avatar answered Dec 21 '22 21:12

Marco