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 6251301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:35:22+00:00 2026-05-24T13:35:22+00:00

SELECT a.tag,CONCAT(u.first_name,’ ‘,u.last_name) FROM assets a LEFT JOIN (SELECT asset_id,assigned_to_id FROM asset_activity WHERE assigned

  • 0
SELECT a.tag,CONCAT(u.first_name,' ',u.last_name)
FROM assets a   
LEFT JOIN (SELECT asset_id,assigned_to_id
       FROM asset_activity
       WHERE assigned IN (SELECT MAX(assigned)
                          FROM asset_activity
                          GROUP BY asset_id)) 
       v ON v.asset_id = a.id
LEFT JOIN users u ON v.assigned_to_id = u.id  
WHERE ($1 IS NULL OR u.last_name LIKE $1)     

Since MySQL performs horribly with left joins on a subquery, I need to find some other method to do this. I can select what I need with subqueries within the select, but it needs to be conditional. It should only return the records that match the LIKE, and with subqueries, it would still return a record from assets with a null value for assigned_to, so I can’t do that.

EXECUTION PLAN:

id select_type        table          type     possible_keys  key     key_len  ref  rows              Extra    
1  PRIMARY            a              ALL      null           null     null    null             1,447
1  PRIMARY            <derived2>     ALL      null           null     null    null             1,396
1  PRIMARY            u              eq_ref   PRIMARY        PRIMARY  4       v.assigned_to_id 1 
2  DERIVED            asset_activity ALL      null           null     null    null             1,400 Using where 
3  DEPENDENT SUBQUERY asset_activity index    null           asset_id 4       null             1,400 Using filesort

INDEXES:

Table   Non_unique        Key_name  Seq_in_index      Column_name       Collation Cardinality Sub_part Packed   Null  Index_type    Comment
assets  0                 PRIMARY   1                 id                A         144         ""                       BTREE       ""    
assets  1                 serial    1                 serial            A         1447                          YES    BTREE       ""
assets  1                 serial    2                 cal_num           A         1447                          YES    BTREE       ""

Table          Non_unique Key_name          Seq_in_index Column_name       Collation Cardinality Sub_part Packed Null Index_type Comment
asset_activity 0          PRIMARY           1            id                A         1400        ""                   BTREE      ""
asset_activity 1          asset_id          1            asset_id          A                     ""                   BTREE      ""
asset_activity 1          location_id       1            location_id       A                                     YES  BTREE      ""
asset_activity 1          assigned_to_id    1            assigned_to_id    A                                     YES  BTREE      ""
asset_activity 1          assigned_to_table 1            assigned_to_table A                                     YES  BTREE      ""
asset_activity 1          created           1            created           A                     ""                   BTREE      ""
  • 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-24T13:35:23+00:00Added an answer on May 24, 2026 at 1:35 pm

    OK, here’s how I finally got it performing:

    SELECT a.tag,CONCAT(u.first_name,' ',u.last_name) 
    FROM assets a    
    LEFT JOIN asset_activity v ON v.asset_id = a.id
    LEFT JOIN asset_activity v2 ON v2.asset_id = a.id 
         AND (v.assigned < v2.assigned OR v.assigned = v2.assigned AND v.id < v2.id)
    LEFT JOIN users u ON v.assigned_to_id = u.id               
    WHERE v2.id IS NULL
      AND ($1 IS NULL OR u.last_name LIKE $1)
    

    This performs far better than the left join on a subquery with a subquery. .0064 sec as compared to 5 sec or more for the other method and it turned into more when binding it to a grid in my code, for paging, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have the following code: <redirect:write select=concat('..\\folder\\,string(filename),'.xml')> Where filename is a tag in
SELECT GROUP_CONCAT(DISTINCT tag) AS tags, filename, COUNT(tag) AS count FROM dados GROUP BY filename
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
While using fixed width select tag , there is one bug in IE. When
I have a easy select tag: <select> <option></option> <option></option> </select> Then I want use
I am trying to disable a select tag. The options to fill our not
Here is my table in the dataset: SELECT tag_work_field.* FROM tag_work_field I created this
Suppose I have a dropdown (select tag) with 3 values. Our first option has
Im trying to define a select tag in my view. My view looks like
I have a problem with adding OPTIONS to SELECT tag dynamically. Here is my

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.