1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ユーザ情報とグループ情報を見やすくするVIEW

Last updated at Posted at 2012-12-26

開発をしていると、どのユーザがどのグループに所属しているかすぐに知りたいことがあります。XOOPSのユーザ管理でユーザ編集を開いて確認することもできますが、SequelProなどのMySQLクライアントアプリでデータベースを直接参照したほうが見やすい場合があります。

その場合は、専用のビューを作っておきます。ビューを作るクエリは次です。

CREATE VIEW user_group_view AS
SELECT 
	U.uid AS user_id,
	U.name AS user_name, 
	U.uname AS user_uname,
	U.email AS user_email,
	G.groupid AS group_id,
	G.name AS group_name
	FROM PREFIX_users as U
	LEFT JOIN PREFIX_groups_users_link as L
		ON U.uid = L.uid
	LEFT JOIN PREFIX_groups as G
		ON L.groupid = G.groupid
	ORDER BY 
		U.uid ASC,
		G.groupid ASC

PREFIX の部分はXOOPSのデータベース接頭辞に置き換えて下さい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?