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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:28:51+00:00 2026-05-26T08:28:51+00:00

I have 2 tables: files and user. files —————————- |Fileid | name | type

  • 0

I have 2 tables: files and user.

files
----------------------------
|Fileid  | name  | type    |
----------------------------
| 01     | file1 | private |
| 02     | file2 | private |
| 03     | file3 | Public  |
----------------------------

and

user
---------------------
| Fileid  | UserId  |
---------------------
| 01      | user1   | 
| 02      | user1   |
---------------------

How would I select all the record(private and public) for who ever id is in the ‘user’ table and only ‘public’ files for any other user where the ‘userid’ is not in the ‘user’ table? please help

  • 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-26T08:28:51+00:00Added an answer on May 26, 2026 at 8:28 am

    If I correctly understand the problem, you are looking for a LEFT JOIN favoring files returning all fields for non-null UserId, or Public only when UserId IS NULL.

    SELECT 
      files.*
    FROM files LEFT JOIN user ON files.Fileid = user.Fileid
    WHERE 
      user.UserId IS NOT NULL
      OR (user.UserId IS NULL AND files.type = 'Public')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

if I have two tables: files(id, owner) and share(file_id, user) , where owner and
I have a database table where the user marks files to be downloaded. Subsequently,
I have an application where a user can upload files and associate the files
Say I have four tables, users , contacts , files , and userfiles .
I have an SSIS package that transfers some tables to CSV files on a
I have two tables: Users and Files . Users table has 10 rows, Files
I have two html files information.html and employee.html. Information.html contains two tables having IDs
I have 4 SQL server(2008 version) tables 1) USER- to store user information (Fields
Scenario. I have a library shelf, library, user, application tables in the database. One
I have a table in SQL Server 2005. alt text http://www.techpint.com/sites/default/files/images/table.JPG I want to

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.