Solved

help needed with Microsoft SQL Server syntax

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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