FYI, I'm using php and MySQL.
I was wondering what is the best way to select a few (and determined) entries in a "metas" table to link them to the principal element.
For more explanations, I have a table "users" which contains principal informations : id, email, nickname. I also have an other table, "users_metas" which contains a lot of differents informations with one entry for an information (i.e. entry1 : avatar for user1, entry2 : connection for user2, ...).
For now, when I need some specifics informations from the metas table, I'm doing it like this :
SELECT u.u_nickname, u.u_email, um1.um_value as u_avatar, um2.um_value as u_connection
FROM users as u
LEFT JOIN users_metas as um1 ON um1.um_uid = u.u_id AND um1.um_name = "avatar"
LEFT JOIN users_metas as um2 ON um2.um_uid = u.u_id AND um2.um_name = "connection_date"
WHERE u.u_id = :u_id
It works, and after a few "benchmarks" it's way faster than doing other SELECT
queries like :
SELECT u.u_nickname, u.u_email,
(SELECT um_value FROM users_metas WHERE um_uid = u.u_id AND um_name = "avatar") as u_avatar,
(SELECT um_value FROM users_metas WHERE um_uid = u.u_id AND um_name = "connection_date") as u_connection
...
But I was wondering if there was a better way to do that. Of course, there is not just avatar
and connection
informations in the metas table, but a lot of others.
Thanks for you advices.
I'm using "metas" term to speak about diverse informations about an element