Hi guys. The project I'm working on has two type of accounts, "people" and "companies". I hold a single "users
" table with all the accounts and just the basic info needed for login (email, pass, etc), and two other tables "user_profiles
" (regular people) and "company_profiles
" (companies) that hold more specific columns for each type, both of the tables linked to the general "users
" table via a "profile_user_id
" column.
Now, the problem: whenever I want to list users that can be both people and companies, I use a:
"select user_id, user_type, concat_ws('', concat_ws(' ', user_profiles.profile_first_name, user_profiles.profile_last_name), company_profiles.profile_company_name) as user_fullname
". When I list these users I know whether they're people or companies by the "user_type
".
Is my approach using concat_ws
the right (optimal) one? I did this instead of select
-ing every *_name
to avoid returning more columns than necessary.
Any protips are very welcome :).
Thanks
EDIT: the query above continues like: from users left join user_profiles on ... left join company_profiles on ...