Beside personal preference, why use [tt]JOIN[/tt] syntax when the same can be acheived by joining columns in the [tt]WHERE[/tt] clause?
using join syntax
without
Code:
CREATE TABLE [Groups]
(
[id] int NOT NULL IDENTITY PRIMARY KEY,
[name] varchar(50) NOT NULL UNIQUE
)
CREATE TABLE [Users]
(
[id] int NOT NULL IDENTITY PRIMARY KEY,
[name] varchar(50) NOT NULL UNIQUE
)
CREATE TABLE [Users_Groups]
(
[group_id] int FOREIGN KEY REFERENCES [Groups]([id]),
[user_id] int FOREIGN KEY REFERENCES [Users]([id])
)
GO
using join syntax
Code:
CREATE PROCEDURE [dbo].[pr_GetUsersByGroupName]
(
@group_name varchar(50)
)
AS
BEGIN
SELECT u.*
FROM [Users_Groups] u_g
JOIN [Groups] g
ON g.[id] = u_g.[group_id]
JOIN [Users] u
ON u.[id] = u_g.[user_id]
WHERE g.[name] = @group_name
END
GO
without
Code:
CREATE PROCEDURE [dbo].[pr_GetUsersByGroupName]
(
@group_name varchar(50)
)
AS
BEGIN
SELECT u.*
FROM [Groups] g,
[Users] u,
[Users_Groups] u_g
WHERE g.[name] = @group_name
AND u_g.[group_id] = g.[id]
AND u_g.[user_id] = u.[id]
END
GO