Hey There I’m trying to figure out the sql code for this:
Assuming I have 4 columns:
ID NAME EMAIL
1 Mike mike@mike.com
2 Bob bob@bob.com
3 Chris
4 Matt
I want to select the last entry not null from email so in this instance it would be looking for bob@bob.com
I tried Coalesce but that seemed to give me values from the column, but not the LAST one entered. MAX I think is only used to ID’s. Any thoughts?
By joining against a subquery which returns only the
MAX(ID). This isn’t necessary in MySQL, but many other RDBMS won’t permit you to include columns other than the aggregate if they are not also in aGROUP BYclause.Note: In either case this only works reliably if your
IDis an auto-incrementing column and you have not meddled with it by inserting rows where previous ids had been deleted.