Monday 30 September 2013

Merge two tables in SQL and only get row with highest number

Merge two tables in SQL and only get row with highest number

I have two user SQL tables with more or less the same data in it and I
want to merge the two tables and only take the user with the highest
MyLevel. Maybe it makes more sense if I show what I have and what I want.
Table One:
MyName, MyDescr, MyLevel, FromDB
John, "Hey 1", 100, DB1
Glen, "Hey 2, 100, DB1
Ive, "Hey 3, 90, DB1
Table Two:
MyName, MyDescr, MyLevel, FromDB
John, "Hey 4", 110, DB2
Glen, "Hey 5", 90, DB2
Ive, "Hey 6", 90, DB2
What I want to archieve (ignore the <--):
MyName, MyDescr, MyLevel, FromDB
John, "Hey 4", 110, DB2
Glen, "Hey 2, 100, DB1
Ive, "Hey 6", 90, DB2 <-- doesn't matter which one as it is the same level
Of course it is possible, but I am really in the dark regarding JOINs and
especially when needing to GROUP it or alike?

No comments:

Post a Comment