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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:19:08+00:00 2026-05-12T13:19:08+00:00

Tables file_logs file_id user_id files id name etc … published_ratings author_id file_id comment etc

  • 0

Tables


file_logs

  • file_id
  • user_id

files

  • id
  • name
  • etc …

published_ratings

  • author_id
  • file_id
  • comment
  • etc …

Scenario


I am creating a download log and need to display which files a user has rated as well as the unrated ones, this has to be done with 1 query.

I already took a crack at this,

SELECT 
  files.*, 
  IF(file_logs.user_id = published_file_ratings.author_id, TRUE, FALSE) AS rated
FROM file_logs
JOIN files
  ON file_logs.file_id = files.id
LEFT JOIN published_file_ratings
  ON file_logs.file_id = published_file_ratings.file_id
WHERE file_logs.user_id = 8
GROUP BY id

The problem with this query is that if an incorrect user came up first the results would be wrong.

The result should be an array of all the files the user has downloaded with a “rated” column depicting if they’ve rated the file or not.

Any help is really appreciated.

  • 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-12T13:19:09+00:00Added an answer on May 12, 2026 at 1:19 pm

    you need to add AND file_logs.user_id = published_file_ratings.author_id to your JOIN clause

    you can also change your IF statement to IF(ISNULL(published_file_ratings.author_id), FALSE, TRUE)

    also, you can now remove the GROUP BY to hide the multiple users. its use here in that manner is incorrect.

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

Sidebar

Related Questions

I have a script that is designed to parse XML postbacks from Ultracart, right
I have a big problem with my server mysql. All worked fine but since
I have a social network The users table is around 60,000 rows The friends
I've been working on a server and I'm starting to implement logging. However, I'm
I use PHP and Oracle, with crontab executing the PHP scripts at scheduled times.
So, I'm working on a database that I will be adding to my future
I have a very simple file upload PHP script. I am testing with a
We have a script on an FTP endpoint that monitors the FTP logs spewed
I have a vbscript which does the following: Open an access 2003 database Run

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.