Answer the question
In order to leave comments, you need to log in
How to make a selection from related tables with grouping and sorting?
There are two tables:
Nodes
=========
NodeId int IDENTITY (1, 1) PRIMARY KEY,
Title nvarchar(50)
Users
=========
UserId int IDENTITY (1, 1) PRIMARY KEY ,
Title nvarchar(50),
NodePtr int
Linked by fields Users.NodePtr --> Nodes.NodeId (one-to-many, sure)
Tables are full. Nodes can contain users, but can also be empty.
You need to get a sorted list of nodes and the users that belong to them (sorted by both node names and user names within the node),
BUT empty nodes must also be displayed.
Is such a request to the server possible?
Answer the question
In order to leave comments, you need to log in
select n.Title , u.Title
from Nodes n
left join Users u
ON( n.NodeId = u.NodePtr )
ORDER BY n.NodeId , u.UserId
Brilliant, thanks! You need to study the basics, otherwise I only read up to Inner join;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question