Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
243 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
Comment Utility
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
Comment Utility
Thanks I will try this
0
 
LVL 31

Expert Comment

by:awking00
Comment Utility
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
Comment Utility
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 31

Accepted Solution

by:
awking00 earned 350 total points
Comment Utility
See attached.
query.txt
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now