Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2012
    Posts
    10

    Exclamation Unanswered: how to find maximum

    Hello Senior,
    My db contains two table Employee_detail and Student_Detail.Employee_detail has Emp_id and Student_Detail has stud_id.Now my problem is that i want to get one maximum no from these two table.

  2. #2
    Join Date
    Feb 2012
    Posts
    6

    finding max().

    Quote Originally Posted by swapnil24 View Post
    Hello Senior,
    My db contains two table Employee_detail and Student_Detail.Employee_detail has Emp_id and Student_Detail has stud_id.Now my problem is that i want to get one maximum no from these two table.
    Hi,

    I'm new to SQL programming at server level, but would like to help in any way I can

    I thought there is a max() function?

    "i want to get one maximum no from these two tables". did you mean to say.....I want to get one maximum from these two joined tables?

  3. #3
    Join Date
    Sep 2001
    Location
    Chicago, Illinois, USA
    Posts
    601
    Something like this?

    Code:
    select  max(i.Emp_id) MaxID
    from    (
            select  Emp_id
            from    Employee_detail
    
            union
    
            select  Emp_id
            from    Student_detail
    	) i
    Ken

    Maverick Software Design

    (847) 864-3600 x2

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    You gave way too few information for us to help you.

    Give us the structure (columns + data types) and some example data of both tables and what data you want as a result of the query.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  5. #5
    Join Date
    Feb 2012
    Posts
    10
    Hello Senior,
    My db has Two tables
    1.Employee_detail it has column name Emp_id as Bigint(50),Emp_First_name as varchar(50)....
    2. Student_detail it has column name Stud_id as Bigint(50),Stud_First_name as varchar(50)...
    suppose, emp_id has maximum value 35 which is get by MAX() function and Stud_id has Maximum value 67 then i want my Query should return answer 67.

  6. #6
    Join Date
    Feb 2012
    Posts
    10
    Hello Senior
    I have got my Answer by PracticalProgrammer. A Special Thanks to Practical Programmer to help me. And also thanks to Mr.Wim and sqls33ker.

  7. #7
    Join Date
    Feb 2012
    Posts
    6

    finding max

    Quote Originally Posted by swapnil24 View Post
    Hello Senior
    I have got my Answer by PracticalProgrammer. A Special Thanks to Practical Programmer to help me. And also thanks to Mr.Wim and sqls33ker.
    Hi Swapnil24,

    I encourage you to post the solutions even though you have it figured out with help from someone outside this thread. This way, all of us can learn something.

  8. #8
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by sqls33ker View Post
    I encourage you to post the solutions even though you have it figured out with help from someone outside this thread.
    not outside -- see post #3
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  9. #9
    Join Date
    Feb 2012
    Posts
    6

    finding max()

    Quote Originally Posted by r937 View Post
    not outside -- see post #3
    oops, nevermind!

  10. #10
    Join Date
    Feb 2012
    Posts
    10
    Hello sqls33ker,
    I am always ready to take the help and give the help to all the forum memeber's bcz we all are one to solve the problems or helps to other.

  11. #11
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by swapnil24 View Post
    Hello Senior,
    suppose, emp_id has maximum value 35 which is get by MAX() function and Stud_id has Maximum value 67 then i want my Query should return answer 67.
    Can I point out that the information is MEANINGLESS!!!
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  12. #12
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Brett Kaiser View Post
    Can I point out that the information is MEANINGLESS!!!
    the more meaningless a homework assignment, the freer your mind to grok its purpose
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •