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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:09:53+00:00 2026-05-25T00:09:53+00:00

I have some thing to do here with subquery but I am not able

  • 0

I have some thing to do here with subquery but I am not able to do.
I want the result from a table with a extra field to show to no of results from other table with a column value from table 1.
table1:

CountryId   Country  ISO2   ISO3

table2:

id     noof_country    state

I have to retrive noof_country count in table 1 as count field

EDIT
my actual tables are

table 1:
ad_id job_country status delete days_left

table 2:
CountryId Country ISO2 status

I have done query in two phase:

$sql_map = "select distinct c.ISO2, c.Country, a.job_country
    from rec_countries c, rec_advert a
    where c.status = 1
    and DATE(a.modified_date) >= CURDATE() - INTERVAL 30 DAY
    and c.ISO2 <> '--'
    and c.ISO2 <> ''
    and c.CountryId = a.job_country
    and a.status = 1
    and a.`delete` = 0
    and a.days_left >0
    ";
$res = mysql_query($sql_map);

while($row = mysql_fetch_array($res)){
    $jobs_no = count($row['job_country']);
    $sql_job = "SELECT COUNT( job_country ) AS jobs_no
    FROM rec_advert
    WHERE job_country = ".$row['job_country']."
    and status = 1
    and `delete` = 0
    and days_left >0";
    $resjob=mysql_query($sql_job);
    $rowjob = mysql_fetch_array($resjob);

    //here jobs_no is the count of total rows
}

Here I want to do with subquery.

  • 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-25T00:09:54+00:00Added an answer on May 25, 2026 at 12:09 am

    If I read the question right, this should work:

    SELECT
        CountryId,
        Country,
        ISO2,
        ISO3,
        (
            SELECT COUNT(DISTINCT noof_country)
            FROM table2
            WHERE table2.id = table1.CountryId
        ) AS noof_country_count
    FROM table1
    

    It’s not immediately clear in your question which column in table1 is a foreign key to which column in table2… or if they are even related that way. If this query doesn’t work for you, please clarify your schema.


    Based on your updated information, try this:

    select distinct c.ISO2, c.Country, a.job_country,
        (
            select COUNT(a2.job_country)
            from rec_advert a2
            where a2.job_country = a.job_country
            and a2.status = 1
            and a2.`delete` = 0
            and a2.days_left >0
        ) as jobs_no
        from rec_countries c, rec_advert a
        where c.status = 1
        and DATE(a.modified_date) >= CURDATE() - INTERVAL 30 DAY
        and c.ISO2 <> '--'
        and c.ISO2 <> ''
        and c.CountryId = a.job_country
        and a.status = 1
        and a.`delete` = 0
        and a.days_left >0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really quick here... I think I have the answer, but just looking for some
I'm reading some articles, even some answers here on stack, but i still have
I have already posted something similar here but I would like to ask the
I hope I am not missing something very simple here. I have done a
I have some small canvas, and i have to show border around them, i
How do I specify the parent query field from within a subquery in MySQL?
I have some thing like this code: map<int, string> m; m[1] = a; m[2]
Here I have some entities in core data, for example, Account, and I wish
I have a situation where I have to do some thing like this for
I'm trying to reference a field from the 1st select table in the 3rd

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.