?
Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Assisted Solution

by:JoeNuvo
JoeNuvo earned 600 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 1400 total points
ID: 35193445
See attached.
query.txt
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 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