Solved

help needed with Microsoft SQL Server syntax

Posted on 2011-03-14
5
244 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 44
Getting certain data from a string 1 34
Left Join with Tuple returning more rows 10 89
SQL Statement to Update Email Domain 2 19
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

930 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

19 Experts available now in Live!

Get 1:1 Help Now