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

  • Home
  • SEARCH
  • 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 8004329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:53:10+00:00 2026-06-04T16:53:10+00:00

I currently have this query running on my website, public function searchCandidates($type=null, $gender=null, $age=null)

  • 0

I currently have this query running on my website,

public function searchCandidates($type=null, $gender=null, $age=null)
{
    //die(var_dump($age));
    if($age != false) {
        $age = implode(", %", $age);
    }

    $sql = 'SELECT `candidates`.`candidate_id`, 
                    `candidates`.`first_name`, 
                    `candidates`.`surname`, 
                    `candidates`.`gender`,
                    `candidates`.`DOB`, 
                    `candidates`.`talent`, 
                    `candidates`.`availability`,
                    `candidates`.`youtube_showreel_1`,
                    `candidates`.`youtube_showreel_desc_1`,
                    `candidates`.`date_created`,
                    `candidates`.`new_talent`,
                     DATE_FORMAT(NOW(), "%Y") - DATE_FORMAT(`candidates`.`DOB`, "%Y") - (DATE_FORMAT(NOW(), "00-%m-%d") < DATE_FORMAT(`candidates`.`DOB`, "00-%m-%d")) as `age`,
                    `candidate_assets`.`url`, 
                    `candidate_assets`.`asset_size`,
                    `candidate_assets`.`weight`
            FROM `candidates`
            LEFT JOIN `candidate_assets` ON `candidate_assets`.`candidates_candidate_id` = `candidates`.`candidate_id`
            WHERE `candidates`.`show_on_site` = "urban talent" AND `candidates`.`visible` = "yes" AND `candidate_assets`.`weight` = 1';
            //is there a certain criteria
            if($type != "0") { $sql .= ' AND `candidates`.`talent` LIKE "%'.$type.'%"'; }
            if($age != false) { $sql .= ' AND `candidates`.`playing_age` LIKE "%'.$age.'%"';}
            if($gender != false){ $sql .= ' AND `candidates`.`gender` = "'.$gender.'"'; }

            $sql .= ' GROUP BY `candidates`.`candidate_id` ORDER BY `candidates`.`surname` ASC, `candidate_assets`.`weight` ASC';

    $query = $this->db->query($sql);

    //die(print_r($query->result_array()));

    //echo $this->db->last_query();
    //die();
    return $query->result_array();
}

I am struggling to get this query working as I wish, I want to show all results regardless of whether or not the user has a image (candidate_assets.url), however if they do have an image then I only need to show the an image that has weight of 1. At the moment, my query only brings back users that have an image that is weighted as 1.

What I want is being back all users, and if they have an image (or multiple images) then return the image that has a weight of 1.

What I am doing wrong?

  • 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-06-04T16:53:12+00:00Added an answer on June 4, 2026 at 4:53 pm

    Your LEFT JOIN makes no difference if you use columns from the second table in your where clause. Either allow them to be NULL in the where clause, or move them to the ON clause:

    You have:

    LEFT JOIN `candidate_assets` 
    ON `candidate_assets`.`candidates_candidate_id` = `candidates`.`candidate_id`
    WHERE `candidates`.`show_on_site` = "urban talent" 
    AND `candidates`.`visible` = "yes" 
    AND `candidate_assets`.`weight` = 1';
    

    Make that:

    LEFT JOIN `candidate_assets` 
    ON `candidate_assets`.`candidates_candidate_id` = `candidates`.`candidate_id`
    AND `candidate_assets`.`weight` = 1 /*moved here*/
    WHERE `candidates`.`show_on_site` = "urban talent" 
    AND `candidates`.`visible` = "yes" 
    

    Or possibly (less “logical”)

    LEFT JOIN `candidate_assets` 
    ON `candidate_assets`.`candidates_candidate_id` = `candidates`.`candidate_id`
    WHERE `candidates`.`show_on_site` = "urban talent" 
    AND `candidates`.`visible` = "yes" 
    AND (`candidate_assets`.`weight` = 1 OR `candidate_assets`.`weight` IS NULL)
    

    Now you will have all the rows you want. To optionally only select an image if there is one, either let your application code handle that or juggle your SELECT clause a bit with an IF-query.

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

Sidebar

Related Questions

I currently have this query: SELECT s_id FROM orderline,order_t WHERE orderline.o_id=order_t.o_id AND c_name='John Smith';
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I have a LINQ query that is currently like this: var query = from
I currently have this script : function addConsultant() { var sheet_staffing = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(Staffing); var
I currently have this... sanitizeNumber = function ( dirtyNumber ){ // remove any non-digits
Currently I have a url like this http://<client_name>.website.com/index.php?function_name&cat=32 I want to set things up
I currently have a query running on my site which looks for all rows
I have this query which works correctly in MySQL. More background on it here
If I have a query like this: String Category = HttpContext.Current.Request.QueryString[Product].ToString(); IQueryable<ItemFile> pressReleases =
I currently have this but it's not flawless: $testcases = array( array(I love mywebsite.com,

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.