【发布时间】:2016-12-23 23:50:38
【问题描述】:
我正在处理的项目有两种类型的帐户,“people”和“companies”。
我持有一个“users”表,其中包含所有帐户以及登录所需的基本信息(电子邮件、密码等),以及另外两个表“user_profiles”(普通人)和“@987654325 @"(公司)为每种类型保存更具体的列,这两个表都通过“profile_user_id”列链接到一般的“users”表。
但是,每当我想列出既可以是个人也可以是公司的用户时,我会使用:
“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”。
当我列出这些用户时,我通过“user_type”知道他们是个人还是公司。
我使用concat_ws 的方法是正确的(最佳)方法吗?我这样做而不是 select-ing 每个 *_name 以避免返回不必要的列。
谢谢
编辑:上面的查询继续如下:from users left join user_profiles on ... left join company_profiles on ...
【问题讨论】:
标签: php mysql optimization