Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:50:50+00:00 2026-05-31T21:50:50+00:00

I am stumped by this one. I have tried several angles and some come

  • 0

I am stumped by this one. I have tried several angles and some come close but none are completely correct.

I need to select from 3 fields of a table. The first is a log_id with a unique number for each row, the second is an entry_id which originates from another table and has multiples of the same entry numbers and the last is a single letter representing a type.
‘D’ means the corresponding entry has been deleted, BTW.

Example:

"SELECT log_id, entry_id, type from entry_log order by entry_id";

…has the following example outcome (a snip of the real query):

6       1       C
31      1       D
8       2       C
25      2       D
11      3       C
14      3       D
13      3       D
18      4       D
17      4       D
12      4       C
22      5       D
15      5       C
398     6       U
249     6       U
44      6       U
587     6       R
272     6       U
498     6       R
578     6       U
590     6       U
529     6       R
564     6       D
43      7       U
42      7       D
16      7       C

I need to choose the highest row[0] value of each row[1] value whose row[2] value equals ‘D’. In other words, the correct choice when row[1] = 6 is where row[0] = 564 in the array above. I need to put a single entry_id(row[1]) with it’s corresponding log_id(row[0]) into another array.

I have tried the following:

"SELECT MAX(log_id), entry_id, type from entry_log where type = 'D'";

This does not account for the fact that some of row1 have entries higher than ones that match D (as they are no longer deleted).

I’ve tried going backward:

"SELECT log_id, entry_id, type from entry_log where log_id in ('U','R','C','x')";

Again not logical.

$log = "SELECT log_id, entry_id, type from entry_log order by entry_id;
$lgcomp = mysql_query($log);
while ($row = mysql_fetch_array($logcomp, MYSQL_NUM)) {
    $cli = $row[0];
    $cei = $row[1];
    $ct = $row[2];
}
foreach ($cli as $key=>$clid)
    if $cei = 

…stumped…

foreach($cli as $key => $clid){
        $lgentry = $cei[$key];

    switch($clid) {
      case $lgentry =   :

        break;

… can’t figure …

I just don’t have the technical understanding of PHP mysql syntax to get this to come out correctly.

Any and all ideas or just pointing me in the right direction will be appreciated. No, you don’t need to write my script (I do like figuring it out which is what this is all about for me) but I have been hashing out a lot of time on this one and I know I am simply missing some syntax and understanding of sorting in PHP/mysql. As far as Internet searching, I only come up with never ending repeats that don’t help in this case.

Thanks! This 72 year old has learned a lot here in the last couple of weeks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:50:51+00:00Added an answer on May 31, 2026 at 9:50 pm

    Try this:

    select el1.* from entry_log el1
    left join (
      select entry_id, log_id from entry_log
      where type = 'D'
    ) el2
    on el1.entry_id = el2.entry_id and el1.log_id < el2.log_id
    where el2.log_id is null and el1.type = 'D'
    

    Result:

    +--------+----------+------+
    | LOG_ID | ENTRY_ID | TYPE |
    +--------+----------+------+
    |     31 |        1 | D    |
    |     25 |        2 | D    |
    |     14 |        3 | D    |
    |     18 |        4 | D    |
    |     22 |        5 | D    |
    |    564 |        6 | D    |
    |     42 |        7 | D    |
    +--------+----------+------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm completely stumped on this one. I have three different lists that need to
This one has me stumped, and none of the other related questions here have
Im stumped by this simple query because its one I have not tried before.
I have to admit I am COMPLETELY stumped on this one. I've been scouring
I really have tried researching this problem, but I'm now getting so close to
I have been very stumped by this one. I have a fairly large (~1500
This one's got me stumped and it's driving me nuts. I have a SiteFinity
I'm relatively(read: stupid newbie) familiar with disassembly but this bit stumped me: I have
I've been stumped for bit on this one - I have a string that
I've dealt with WP js conflicts before, but this one has me stumped. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.