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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:57:07+00:00 2026-06-01T22:57:07+00:00

I have 2 tables : Users and Documents . 1 User can have 0

  • 0

I have 2 tables : Users and Documents.

1 User can have 0 or several documents.

I would like to display each user and their documents, but the problem : I would like to display users that have no documents, in a result like this (assume IdUsers 3 and 5 have no documents):

IdUser IdDocument DocumentName
====== ========== ============
1      1          test11.pdf
1      2          test12.pdf
1      3          test13.pdf
2      4          test21.pdf
2      5          test21.pdf
3      NULL       NULL
4      6          test41.pdf
5      NULL       NULL
  • 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-01T22:57:09+00:00Added an answer on June 1, 2026 at 10:57 pm

    You will use a LEFT JOIN to perform this operation.

    create table users
    (
      userid int
    )
    
    create table documents
    (
      documentid int,
      userid int,
      documentname varchar(10)
    )
    
    insert into users values (1)
    insert into users values (2)
    insert into users values (3)
    insert into users values (4)
    
    insert into documents values (1, 1, 'test')
    insert into documents values (2, 1, 'test 1')
    insert into documents values (3, 2, 'test 2')
    insert into documents values (3, 3, 'test 3')
    
    select *
    from users u
    left join documents d
    on u.userid = d.userid
    

    see a sqlfiddle for a test

    You should do some research on JOINs, here is a good description of the JOINs:

    A Visual Explanation of SQL Joins

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

Sidebar

Related Questions

I have 2 tables: users (user_id, user_connected) rooms (room_id, room_initiating_user_id, room_target_user_id) I would like
I have two tables users and providers that have has_and_belongs_to_many relationship. The join table
I have 2 tables: users and subscribers . The relationship of the user to
I have the following situation: excel-like application, that is accessible from internet. 2 users
I currently have a model that the user can upload a thumbnail to the
I have tried several different submit buttons but can not seem to get this
I have two tables users and work_orders. Now I need to get work_orders results
I have these tables: users ----- id INT name VARCHAR(20) email VARCHAR(40) user_fans ----------
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many

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.