How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Russell H. Your Own Question
Russell H.
Russell H., Programmer & Coder
Category: Programming
Satisfied Customers: 10919
Experience:  Programmer & Coder
Type Your Programming Question Here...
Russell H. is online now
A new question is answered every 9 seconds

I have the following query: SELECT s.account_number, AS

Customer Question

I have the following query: SELECT s.account_number, AS 'ASPIRION ID', a.patient_first_name, a.patient_last_name, s.admission_date, s.total_charge, AS 'STATUS', astat.definition, latest_note.content AS 'LAST NOTE', a.insurance_company FROM
accounts a INNER JOIN services s ON = s.account_id INNER JOIN facilities f ON = a.facility_id INNER JOIN account_statuses astat ON = a.account_status_id INNER JOIN (SELECT account_id, MAX(content) content, MAX(created) FROM notes GROUP BY
account_id) latest_note ON latest_note.account_id = WHERE a.facility_id = 56 My problem is with "(SELECT account_id, MAX(content) content, MAX(created)" I need to be able to get the content associated with the max id but im not sure how to tell it to
do that
Submitted: 2 years ago.
Category: Programming
Expert:  Russell H. replied 2 years ago.
Hi, thank you for contacting My name is***** will do my best to provide the right answer to your question.
Generally the MAX() function will return the maximum or largest/highest value in a field.
So if you do
SELECT MAX(first_field) FROM example_table
then you will get the largest value in that field. If that field in that table has values in an assortment like this:
then what will be returned is
So if you want the content in the record that has '59' as its 'first_field' value, you would do
SELECT * FROM example_table WHERE first_field=MAX(first_field)
or the like.
Customer: replied 2 years ago.
Content is a varchar field. So how would I get the most recent entry
Expert:  Russell H. replied 2 years ago.
That depends upon how the most recent entry in the table may be distinguished from the other entries. Is there a time-stamp field, for instance, that is larger in value when you create a later entry in the table? or is there some other means of telling the most recent or latest entry in the table by a field value?