Get last non-empty field

Is my strategy for finding the last non-empty field in a database column okay? I was thinking of selecting all non-empty fields in that column, ordering them by id DESC, then using LIMIT 1.

Is there a better way to do this?

Thanks.

Hi, I think your method should work but have you checked out last() function in SQL?

Here is a full documentation link, and you can see that the workarounds are very similar to your described method:

http://www.w3schools.com/sql/sql_func_last.asp

From what I have read so far, the last() function does not work in mySQL.

Why do you want to do this?

Perhaps if you explain the problem you try to solve it will be easier to help you. The solution you suggested can work, or not all depending on what you plan to do with the information.

[quote=“WebMachine, post:1, topic:209020, full:true”]
Is my strategy for finding the last non-empty field in a database column okay?[/quote]

“last” implies a sequence… you seem to suggest you want the highest id… why?

A form is submitted numerous times over a period of days or weeks. One of the fields is next_meeting_date. This field is not filled in unless the user wants to add a new meeting date or change the current next_meeting_date, so often the field will be NULL or empty. I want to post the next meeting date at the top of the form when it is displayed.

So actually it is not the id I want to order by, but the meeting date. My logic was wrong there in the O.P.

[quote=“WebMachine, post:6, topic:209020, full:true”]So actually it is not the id I want to order by, but the meeting date. My logic was wrong there in the O.P.
[/quote]

so your problem is now solved?

I haven’t had a chance to try it yet - I’m working on another project today. I’ll report back later. Thanks.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.