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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:54:24+00:00 2026-05-26T05:54:24+00:00

I have the below query and it works perfect , no issues SELECT description

  • 0

I have the below query and it works perfect , no issues

SELECT description category,
      details,
      created_by,
      CONCAT(name,' ',surname) name,
      FROM_UNIXTIME(createdon) created_date,
      FROM_UNIXTIME(updatedon) updated_date,
      comments_count,
      entry_id,
      code car_code
FROM my_area_details,my_user,my_master_area_categories 
WHERE type=4 
AND code IN ( SELECT car_code 
             FROM my_cars
         WHERE car_company='GM' 
             AND car_model='Chevy') 
AND my_area_details.created_by=my_user.user_id 
AND my_area_details.category=my_master_area_categories.type_id
ORDER BY category

In the above query the below sub query returns only one value or nothing

 SELECT car_code 
 FROM my_cars
 WHERE car_company='GM' 
 AND car_model='Chevy'

In First query if my other tables doesn’t have any matching records I get zero records .

My requirement is if the the sub query has value and the main query not returning any records ( due to records not found in other tables) , I should at least get the value of car_code from my_cars (Other values can be NULL).

For that I tried adding subquery as alias table and did left join with that alias table ,
But since I have other conditions I am still not getting car code .Also tried doing joining on the other three table and with the result doing the left join with my_car table . But this one taking time since I am not checking against car code in the first level query

Any way to Join and get the car_code from my_cars table even if my other tables doesn’t have any thing matching …?

  • 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-26T05:54:24+00:00Added an answer on May 26, 2026 at 5:54 am

    You can left join the rest of the tables agains car_code, thus making car_code the leading query.
    Or right join car_code to your current query, which essentially has the same effect, but I would recomment not to mix left join and right join.

    Problem is that you will always need a car_code, or else you won’t get other data back (same problem you got now, but the other way around), but as I read your requirements, this should not be a problem:

    I strongly advise you to use more consistent field names across tables, and to use INNER and LEFT joins, and table aliasing for readability. Your query could look like this, although it’s not complete since I don’t know the exact relations between your tables.

       SELECT description category,
              details,
              created_by,
              CONCAT(name,' ',surname) name,
              FROM_UNIXTIME(createdon) created_date,
              FROM_UNIXTIME(updatedon) updated_date,
              comments_count,
              entry_id,
              code car_code
         FROM car_code cc
    LEFT JOIN my_area_details ad ON ad.code = cc.car_code 
                                AND ad.type = 4 
    LEFT JOIN my_user u ON u.user_id = ad.created_by
    LEFT JOIN my_master_area_categories mac ON mac.type_id = ad.category
        WHERE car_code.car_company = 'GM'
          AND car_code.car_model = 'Chevy'    
     ORDER BY category
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with the query below in postgres SELECT u.username,l.description,l.ip,SUBSTRING(l.createdate,0,11) as createdate,l.action
I have a very large query that follows the format below: select ... from
I have written an SQL script having the below query. The query works fine.
I have a query like below... SELECT contents.id, contents.title, contents.createdBy, (SELECT userGroup FROM suser_profile
I have the below query... It works but it runs extremely slow. Was hoping
I have this live search which works perfect until a company name in my
I have a query below that works but was wondering if there is a
I have some problem regarding the search in mysql. Below is my query. SELECT
This query below works but i seem to have a weird bug. The first
I have below query I am trying to show message 'No SubSource for this

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.