[英]SQL Query - Distinct on One Column for Distinct Value of Other (with INNER JOIN)
[英]How to make Distinct Column in a View while on Inner Join - SQL
每個視圖或函數中的列名必須唯一。 'v_userStatus'
指定視圖或函數'v_userStatus'
列名'ur_id'
CREATE VIEW v_userStatus AS
select *
from tbl_user inner join
tbl_userrole
on tbl_user.u_user_role_id = tbl_userrole.ur_id
where tbl_user.u_isDelete = 0 and tbl_userrole.ur_id = 2;
不要使用select *
。 您可以從tbl_user
獲取所有列,然后從用戶角色中獲取其他列:
CREATE VIEW v_userStatus AS
select u.*, ur.?, ur.?
from tbl_user u inner join
tbl_userrole ur
on u.u_user_role_id = ur.ur_id
where u.u_isDelete = 0 and ur.ur_id = 2;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.