• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Neeq a SQL query

Experts,
As per my attachment, could you please get me a query?
Thanks in advance.
test.docx
0
Tpaul_10
Asked:
Tpaul_10
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
sshah254Commented:
What decides if 1233 or 1234 from Table1 should be selected?

Ss
0
 
Ephraim WangoyaCommented:

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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ephraim WangoyaCommented:
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
 
Tpaul_10Author Commented:
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
 
sshah254Commented:
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
 
Ephraim WangoyaCommented:

A quick look at the results tells me its max values
0
 
SharathData EngineerCommented:
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
 
Tpaul_10Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now