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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:16:52+00:00 2026-05-25T02:16:52+00:00

Please help me to structure mysql query I have 2 tables, #_ udjacomment AND

  • 0

Please help me to structure mysql query

I have 2 tables, #_udjacomment AND #_content

currently I have query:

$query  = "SELECT udja.id";

      if( $include_author == 1 ) $query .= ", udja.full_name";
      if( $include_date == 1 ) $query .= ", udja.time_added";
      if( $include_comment == 1 ) $query .= ", if(CHAR_LENGTH(udja.content) > ".$content_number_of_characters.", SUBSTR(udja.content, 1, ".$content_number_of_characters."), udja.content) AS content";
      if( $include_link_to_comment == 1 ){ 
        $query .= ", CASE WHEN LOCATE('com_content:', udja.comment_url) > 0 
        THEN CONCAT(SUBSTRING_INDEX(udja.comment_url,':',-1),'-', com_content.alias, '.html')
        ELSE udja.comment_url END AS comment_url";
        }

      $query .= " FROM #__udjacomments AS udja, #__content AS com_content WHERE udja.is_published = 1 AND com_content.id = SUBSTRING_INDEX(udja.comment_url,':',-1) AND com_content.checked_out = 0 ORDER by udja.id DESC limit ".$number_of_comments;

But I am not getting the proper results. If I stop trying to access from the table #__content AS com_content, then I get the results for #__udjacomment AS udja correct

So, I guess I am asking how can indicate and include the constrain that I want the field com_content.alias WHERE com_content.id = SUBSTRING_INDEX(udja.comment_url,':',-1)

In some cases, udja.comment_url will have this format com_content:22, com_content:19

and in other instances, udja.comment_url will have a string like word-word-another-word

this is why I have the more extensive statement inside the conditional if($include_link_to_comment == 1)

UPDATE: THE FINAL QUERY LOOKED LIKE THIS (I IMPLEMENTED WHAT RESPONDER SUGGESTED AND CHANGED THE CASE STATEMENT AND THE WHERE STATEMENT)

 $query  = "SELECT udja.id";

      if( $include_author == 1 ) $query .= ", udja.full_name";
      if( $include_date == 1 ) $query .= ", udja.time_added";
      if( $include_comment == 1 ) $query .= ", if(CHAR_LENGTH(udja.content) > ".$content_number_of_characters.", SUBSTR(udja.content, 1, ".$content_number_of_characters."), udja.content) AS content";
      if( $include_link_to_comment == 1 ){ 
        $query .= ", CASE 
            WHEN LOCATE('com_content:', udja.comment_url)<>0
            THEN CONCAT(SUBSTRING_INDEX(udja.comment_url,':',-1),'-', com_content.alias, '.html')
            ELSE udja.comment_url 
            END AS comment_url";

        }
//          THEN CONCAT(SUBSTRING_INDEX(udja.comment_url,':',-1),'-', com_content.alias, '.html')
      $query .= " FROM #__udjacomments AS udja
                    LEFT JOIN #__content AS com_content 
                        ON com_content.id = SUBSTRING_INDEX(udja.comment_url,':',-1) 
                    WHERE udja.is_published = 1 ORDER by udja.id DESC limit ".$number_of_comments;
  • 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-25T02:16:53+00:00Added an answer on May 25, 2026 at 2:16 am

    You need to use an outer join:

    ...
    FROM #__udjacomments AS udja
    LEFT JOIN #__content AS com_content 
        on com_content.id = SUBSTRING_INDEX(udja.comment_url,':',-1)
    WHERE ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help! Background info I have a WPF application which accesses a SQL Server
i know it may be very simple query, but please help me out. i
Please help me in finding the optimized solutions to these interesting data structure questions:
can someone please help me turn this nested structure into a single LINQ statement?
Please help me in creating LaTeX document with the following structure Text Author Text
please help. I have this code, it's my class to serialize\deserialize application settings. [XmlRoot(EvaStartupData)]
I have following db structure in mysql. Table: Story Id Name categoryid date 1
Currently I'm developing a website with MYSQL INNODB and I need someone to help
I have got a native join sub query problem in MySQL Entity. SQL code
I need a small help in making a mysql database structure I am making

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.