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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:29:04+00:00 2026-06-04T09:29:04+00:00

I have two tables: doc_types: doc_id | doc_name | expiry_days ——-|———-|————- 1 | Doc_1

  • 0

I have two tables:

doc_types:

doc_id | doc_name | expiry_days
-------|----------|-------------
  1    | Doc_1    |    365
  2    | Doc_2    |    90
  3    | Doc_3    |    30

docs_supplied:

evidence_id | doc_id  | client_id |  date_supplied
------------|---------|-----------|-----------------
       1    | 1       |    5432   |   13-05-2012
       2    | 1       |    3165   |   25-04-2011
       3    | 2       |    5432   |   23-10-2011

The output I would like to see is:

   doc_id | doc_name | expiry_days | client_id |  date_supplied
   -------|----------|-------------|-----------|----------------
     1    | Doc_1    |    365      |    5432   |  13-05-2012
     2    | Doc_2    |    90       |    5432   |  NULL    
     3    | Doc_3    |    30       |    5432   |  NULL
     1    | Doc_1    |    365      |    3165   |  25-04-2012
     2    | Doc_2    |    90       |    3165   |  NULL    
     3    | Doc_3    |    30       |    3165   |  NULL

Essentially for each client, I want to show the complete list of documents (14) but with the extra fields for date supplied etc populated, should there be an entry for that client and document in the DB. So for each client record I’d expect there to be 14 rows, one for each doc_type. Some of these rows will have client-specific data in them.

This is so that in my grid I can just filter against a client_id and see the list of all documents and their status for that person.

Is this possible?

  • 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-04T09:29:05+00:00Added an answer on June 4, 2026 at 9:29 am
    SELECT   doc_types.*, client_id, date_supplied
    FROM     doc_types
       CROSS JOIN (SELECT DISTINCT client_id FROM docs_supplied) AS clients
       LEFT  JOIN docs_supplied USING (client_id, doc_id)
    ORDER BY client_id DESC, doc_id
    

    See it on sqlfiddle.

    If you have a table with a unique client_id column, you can simply use that instead of generating it from the SELECT DISTINCT subquery:

    SELECT   doc_types.*, client_id, date_supplied
    FROM     doc_types
       CROSS JOIN client_accounts
       LEFT  JOIN docs_supplied USING (client_id, doc_id)
    ORDER BY client_id DESC, doc_id
    

    Learn about SQL joins.

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

Sidebar

Related Questions

i have two tables attachments: name, doc_name, doc_type, doc_size, cat and media: name, doc_name,
I currently have two tables, one with documents, and another with ratings doc_id |
i have two tables products and reviews each product has several reviews linked by
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables on a webform. On a button click I want to
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,
I have two tables: Videos -------------- VideoID VideoGroupID CreatorUserID and VideoTags -------------- VideoID TagID
I have two tables, one for routes and one for airports. Routes contains just
I have two tables, for example: Table A Table B ======= ======= Name |

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.