Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
248 Views
Last Modified: 2012-05-11
Excuse the pseudo-code..:

select field1, field2, field3 from table1
group by field1, field2, field 3 as s1

select field1, field2, field3,field4,field5 from table1 as s2

left join s1 to s2 (on s1.field1, s1.field2, s1.field3 = s2.field1, s2.field2, s2field3)
0
Comment
Question by:Jimmy_inc
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:JoeNuvo
JoeNuvo earned 150 total points
ID: 35135521
not sure what are you trying to do.
since both s1 and s2 coming from table1

but query may look like this

SELECT 
	S1.*, S2.*
FROM 
	(SELECT DISTINCT Field1, Field2, Field3 FROM Table1) S1
	LEFT JOIN
	(SELECT Field1, Field2, Field3, Field4, Field5 FROM Table1) S2
	ON  S1.Field1 = S2.Field1
	AND S1.Field2 = S2.Field2
	AND S1.Field3 = S2.Field3

Open in new window

0
 

Author Comment

by:Jimmy_inc
ID: 35135530
Thanks I will try this
0
 
LVL 32

Expert Comment

by:awking00
ID: 35139297
That doesn't make any sense. It's the same as selecting field1, field2, field3, field1, field2, field3, field4, field5 from table1, which is not allowed anyway without creating aliases for the columns. Perhaps you can provide some sample data and the expected results so we gain a better understanding of what you are trying to accomplish.
0
 

Author Comment

by:Jimmy_inc
ID: 35193379
Yeah good point. What I should of posted was :

select field1, field2, field3 from table1
group by field1, field2, max(field 3) as s1

select field1, field2, field3,field4,field5 from table1 as s2

left join s1 to s2 (on s1.field1, s1.field2, s1.field3 = s2.field1, s2.field2, s2field3)

. Although I realise my question has now been answered in a previous post.
0
 
LVL 32

Accepted Solution

by:
awking00 earned 350 total points
ID: 35193445
See attached.
query.txt
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question