Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need sql querry to get maximum of mobile_Id from two Tables (Mobile,DeletedMobile) can anyone help me please ?

What I have tried:

VB
com = New SqlCommand("SELECT Max(Mobile_Id) FROM Mobile UNION SELECT MAX(Mobile_Id) FROM DeleteMobile", con)
        con.Open()
        com.ExecuteNonQuery()

        If IsDBNull(com.ExecuteScalar) Then

            InsertMobile.TextBox1.Text = ""
            InsertMobile.TextBox1.Text = 1
        Else

            InsertMobile.TextBox1.Text = ""
            InsertMobile.TextBox1.Text = com.ExecuteScalar + 1
        End If


        con.Close()
Posted
Updated 1-Mar-20 16:12pm
v2

1 solution

Taken this is SQL Server, you could try something like

SQL
SELECT MAX(a.Mobile_Id)
FROM (SELECT Max(b.Mobile_Id) AS Mobile_Id
      FROM Mobile b
      UNION 
      SELECT MAX(c.Mobile_Id) AS Mobile_Id
      FROM DeleteMobile c) a
 
Share this answer
 
Comments
Member 14609980 1-Mar-20 14:49pm    
thank You Friend
Wendelius 1-Mar-20 14:53pm    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900