Reputation: 31
what does the m. and r . mean? Is it referencing to a table name by its first letter?also other commands like dayname
i have tables called room,employee,meeting, and participants.
select dayname(m.date), count(*) from meeting m, room r where m.room_id=r.room_id group by weekday(m.date) order by weekday(m.date);
Thanks for taking your time on this to answer me
EMPLOYEE: +-----------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+----------+------+-----+---------+-------+ | staff_id | int(11) | NO |PRI | NULL | | | seniority | int(11) | YES | | NULL | | | lastname | char(30) | YES | | NULL | | | firstname | char(30) | YES | | NULL | | +-----------+----------+------+-----+---------+-------+
MEETING: +------------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+----------+------+-----+---------+-------+ | meeting_id | int(11) | NO |PRI | NULL | | | room_id | int(11) | YES |MUL | NULL | | | name | tinytext | YES | | NULL | | | date | date | YES | | NULL | | +------------+----------+------+-----+---------+-------+
PARTICIPANT: +------------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------+------+-----+---------+-------+ | meeting_id | int(11) | YES |MUL | NULL | | | staff_id | int(11) | YES |MUL | NULL | | +------------+---------+------+-----+---------+-------+
ROOM: +---------+----------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+----------+------+-----+---------+-------+ | room_id | int(11) | NO |PRI | NULL | | | name | char(50) | YES | | NULL | | +---------+----------+------+-----+---------+-------+
Upvotes: 0
Views: 91
Reputation: 2496
m
and r
are aliases for the table names meeting
and room
. In this case, it's syntactically convenient to reference them by these names rather than writing the entire table name out.
SELECT * FROM my_table t WHERE t.my_column_name = 123;
In the above example, t
is a convenient way to specify my_table
. You can then access columns (attributes) by specifying t.my_column_name
.
See this for a general explanation:
http://en.wikipedia.org/wiki/Alias_(SQL)
Regarding dayname
, I'm tempted to say that this is a user-defined SQL function, located elsewhere in the code. As far as I can tell, this is not reserved. I suggest you look through the rest of the SQL you have and see if you can find where it has been defined.
Upvotes: 1
Reputation: 34418
Yes, they're aliases for the table names. You defined them yourself in the 'from' section:
from meeting m, room r
Here you are defining m
as an alias for the meeting
table and r
for room
. This can be particularly useful if you e.g. joined against the room table twice: you can then give the two instances different aliases.
Upvotes: 0