• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

where max

Guest
Mar 05, 2007 Mar 05, 2007

Copy link to clipboard

Copied

gday just have a small problem.

i need to have a select statement like below, but this gives me an error, any ideas how to do this

so what i need is to select all where the number matches and then select the last record of this number

<CFQUERY datasource="#application.ds#" Name="Show">
SELECT *
FROM sms_records
WHERE NumberSent = '421365488' AND ID = Max(ID)
</cfquery>
TOPICS
Advanced techniques

Views

259

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Mar 05, 2007 Mar 05, 2007
ok thanks, I have done that but it returns every id in the table? i just need it to select the last id number

<CFQUERY datasource="#application.ds#" Name="Show66">
SELECT *
FROM sms_records
WHERE NumberSent = '421365488' AND ID = (SELECT MAX(ID)AS ID FROM sms_records GROUP BY ID)
</cfquery>

Votes

Translate

Translate
LEGEND ,
Mar 05, 2007 Mar 05, 2007

Copy link to clipboard

Copied

put the max(id) into a subquery.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 05, 2007 Mar 05, 2007

Copy link to clipboard

Copied

ok thanks, I have done that but it returns every id in the table? i just need it to select the last id number

<CFQUERY datasource="#application.ds#" Name="Show66">
SELECT *
FROM sms_records
WHERE NumberSent = '421365488' AND ID = (SELECT MAX(ID)AS ID FROM sms_records GROUP BY ID)
</cfquery>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 05, 2007 Mar 05, 2007

Copy link to clipboard

Copied

LATEST
Take away the group by clause in the subquery.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation