I have a table that I'm trying to clear, so I'm the first in the table for each table I use the query: result = < / P> expected result = This needs to work for n clients I tried is the resultant error in the SELECT * FROM addresses group (the column 'id' is invalid in the selection list because it is not a composite function or a block by group.) What's missing here? SQL Server requires that when you use a group, you can select columns in the selected list Must use a composite function or add them to Group BY. Your original query can be changed to use the following: As you can see, it uses a subquery which gives the ClientId The address should be
addresses in these columns
Pk [Id] [ClientId] [AddressLine1] [AddressLine2] < / Code>
select
* ORDER client ID
1 1 fu bar 2 1 fu 2 times 2 3 fu 3 times 3 4 1 fu 4 times 4 5 2 fu times 2 9 2 fu times 5 97 2 fu times 6 8 3 fu 2 times 7
1 1 foo bar & lt; - The first match for the client is - 1 5 2 foo bar2 & lt; - The first match for the client is - 2 8 3 foo2 times 7 & lt; - The first match for the client is = 3
The customer id
An .id, a.clientid, a.address1, ClientID, client ) Select from IDE Client from address group) at a.clientid = d.clientid and a.id = d.id;
minimum for each
clientId , It only
clientid . Then you join this table to return only those rows with the minimum ID for each customer.
No comments:
Post a Comment