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: 9547
Experience:  Programmer & Coder
13568747
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, a.id AS

Customer Question

I have the following query: SELECT s.account_number, a.id AS 'ASPIRION ID', a.patient_first_name, a.patient_last_name, s.admission_date, s.total_charge, astat.name AS 'STATUS', astat.definition, latest_note.content AS 'LAST NOTE', a.insurance_company FROM
accounts a INNER JOIN services s ON a.id = s.account_id INNER JOIN facilities f ON f.id = a.facility_id INNER JOIN account_statuses astat ON astat.id = 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 = a.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: 1 year ago.
Category: Programming
Expert:  Russell H. replied 1 year ago.
Hi, thank you for contacting JustAnswer.com. 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:
6
2
59
53
14
9
21
then what will be returned is
59
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 1 year ago.
Content is a varchar field. So how would I get the most recent entry
Expert:  Russell H. replied 1 year 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?