?
Solved

Neeq a SQL query

Posted on 2011-03-10
9
Medium Priority
?
276 Views
Last Modified: 2012-06-27
Experts,
As per my attachment, could you please get me a query?
Thanks in advance.
test.docx
0
Comment
Question by:Tpaul_10
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 9

Expert Comment

by:sshah254
ID: 35100479
What decides if 1233 or 1234 from Table1 should be selected?

Ss
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 200 total points
ID: 35100520

select A.Column1, b.Column1, MAX(A.Column3) [Column3]
from Table1 A
inner join Table2 B on B.Column1 = A.Column2
group by A.Column1, b.Column1
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35100522
I presume you need to review the specs ... because I don't see an explanation why table2 is actually needed, and I see no explanation on why row2 from table1 is returned and why not row1.

meanwhile, you might want to read this article, I presume it will help you:
http://www.experts-exchange.com/A_3203.html
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35100557
My mistake


select MAX(A.Column1) [Table1 Column1], B.Column1 [table2 Column1], MAX(A.Column3) [Column3]
from Table1 A
inner join Table2 B on B.Column1 = A.Column2
group by B.Column1
0
 

Author Comment

by:Tpaul_10
ID: 35100585
Basically I need the max value from table1 and for some rows, it is returning the both the rows even though I have used max(column1) in my query. Not sure why
Thanks
0
 
LVL 9

Expert Comment

by:sshah254
ID: 35100600
ewangoya,

We don't know why he is selecting one row over the other - maybe it should be max, maybe min, maybe first, maybe last ... :-)

Ss
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35100654

A quick look at the results tells me its max values
0
 
LVL 41

Accepted Solution

by:
Sharath earned 800 total points
ID: 35101245
try this.
SELECT t1.Column1, 
       t2.Column1, 
       t1.Column3 
  FROM table1 t1 
       JOIN (  SELECT Column2, 
                      MAX(Column1) Column1 
                 FROM table1 
             GROUP BY Column2) AS t11 
         ON t1.Column1 = t11.Column1 
            AND t1.Column2 = t11.Column2 
       JOIN table2 t2 
         ON t1.Column2 = t2.Column2

Open in new window

0
 

Author Closing Comment

by:Tpaul_10
ID: 35110909
Thanks for all your help guys and just to let you know I don't have to review my specs since it was pretty straight forward and I didn't specify all the columns in my tables and I wanted the maximum value.

Sharath's solution gave me the correct results. once again THANKS to all for quick response.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

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