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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:53:39+00:00 2026-06-13T22:53:39+00:00

i am not able to get single value from table b in subquery which

  • 0

i am not able to get single value from table b in subquery which is required in outer query. in table b there is group of dates related to table a and table c. and here i required purpose code of the latest date for the successfull execution of query. if i remove subquery and write where c.purpose_code = b.purpose_code it runs ok but the result is older.
please help me out.

SELECT
  a.filing_no AS "File No",
  a.case_no AS "Registration No",
  a.pet_name AS Petitioner,
  a.res_name AS Accused,
  a.dt_of_filing AS "Date of Inst",
  max(b.Next_date) AS "Next Date",
  c.purpose_name AS "Case Stage"
FROM
  filing_t a, Daily_proc b, Purpose_t c
WHERE
  a.filing_no = b.filing_no
  AND c.purpose_code = (
    SELECT purpose_code FROM Daily_proc
    WHERE filing_no = a.filing_no AND next_date = max(next_date)
    )
  AND a.court_no = 1
  AND a.ci_cri = 2
  AND a.status = 'P'
GROUP BY
  b.filing_no
ORDER BY
  a.dt_of_filing DESC
LIMIT
  0, 2000
  • 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-13T22:53:39+00:00Added an answer on June 13, 2026 at 10:53 pm

    The problem is a subquery –

    SELECT purpose_code FROM Daily_proc
    WHERE filing_no = a.filing_no AND next_date = max(next_date)
    

    Try this query instead –

    SELECT
      purpose_code
    FROM
      Daily_proc
    WHERE
      filing_no = 20 AND next_date = (SELECT MAX(next_date) FROM Daily_proc);
    

    Create tables:

    CREATE TABLE A(
      filing_no INT,
      pet_name VARCHAR(20),
      res_name VARCHAR(20),
      court_no INT);
    INSERT INTO A VALUES
      (1, 'xyz', 'PQR', 1),
      (2, 'abc', 'def', 2);
    
    CREATE TABLE B(
      filing_no INT,
      purpose_code INT,
      next_date DATE);
    INSERT INTO B VALUES
      (2, 20, '2012-8-3'),
      (1, 21, '2012-9-3'),
      (2, 22, '2012-10-3'),
      (1, 23, '2012-11-15');
    
    CREATE TABLE C(
      purpose_code INT,
      purpose_name VARCHAR(20));
    INSERT INTO C VALUES
      (20, 'institution'),
      (21, 'summon'),
      (22, 'proceeding'),
      (23, 'order');
    
    SELECT a.filing_no, a.pet_name, a.res_name, c.purpose_name, b.next_date FROM a
      JOIN (SELECT * FROM (
              SELECT * FROM b ORDER BY filing_no, next_date DESC
           ) t GROUP BY filing_no) b
        ON a.filing_no = b.filing_no
      JOIN c
        ON b.purpose_code = c.purpose_code
    WHERE a.court_no = 1;
    

    Result:

    +-----------+----------+----------+--------------+------------+
    | filing_no | pet_name | res_name | purpose_name | next_date  |
    +-----------+----------+----------+--------------+------------+
    |         1 | xyz      | PQR      | order        | 2012-11-15 |
    +-----------+----------+----------+--------------+------------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

not able to get this, can someone help for this LINQ query? select col1,
I have few Question for which I am not able to get a proper
I am able to get both the value and row of the mysql query
I am not able to get the hg head or status for a given
I'm not able to get this persistence file correct... I do not find any
I am not able to get my jwysiwyg and Jhtmlarea text editors to work
i tried to search this but was not able to get any proper help.I
This seems like a repeated question but i'm not able to get my answer.
I've read the DateFormatting guide and I'm still not able to get a working
I know this is simple but I am not able to get it right

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.