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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:06:30+00:00 2026-06-06T23:06:30+00:00

I have two tables in the database: Article ——————————————– articleID INTEGER PRIMARY KEY AUTOINCREMENT

  • 0

I have two tables in the database:

Article
--------------------------------------------
articleID INTEGER PRIMARY KEY AUTOINCREMENT
userID    VARCHAR

Rating
--------------------------------------------
articleID INTEGER
userID    VARCHAR
rating    INTEGER

Sample data:

Article
articleID        userID
---------------------------------
1                12345
2                23456
3                23456
4                99999
5                15678

Rating
articleID        userID        rating
--------------------------------------------
1                12345         7.5
2                12345         8.5
2                31359         7.5
1                24021         0.0
1                25012         7.5

I want to get all the articles and show if I have rated them or not. I tried and I can only get the list with rated article with this statement:

SELECT a.*, rating AS myRating FROM Article AS a 
LEFT JOIN Rating AS b
ON a.articleID = b.articleID
WHERE (b.userID is NULL || b.userID = "12345") 

How can I join the tables to get the result?

Expected output (with userID 12345)
articleID        userID        myRating
--------------------------------------------
1                12345         7.5
2                23456         8.5
3                23456         NULL
4                99999         NULL
5                15678         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-06T23:06:32+00:00Added an answer on June 6, 2026 at 11:06 pm

    The WHERE-clause will filter out the columns where userID is not 12345 or NULL…

    SELECT a.*, rating AS myRating 
    FROM Article AS a 
    LEFT JOIN Rating AS b
    ON a.articleID = b.articleID 
    AND b.userID = "12345"
    

    Since you want to show all lines of a, put the user-id restriction in the ON clause. Now it will get all lines from A, with NULL for rating if the userid was not 12345.

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

Sidebar

Related Questions

I have two database tables with the following structure: actions: action_id int(11) primary key
I have two database tables, 1st is the TABLE_GLOBAL_PRODUCTS where all products information are
I have two tables in my database schema that represent an entity having a
I have two tables in my database. Comments CommentsID MembersID CommentsBy CommentsDesc CommentsActive CommentsDateEntered
I have two tables in my database: user and media_contact . The media_contact table
I have two tables in my database that look like that: Customer: C_ID city
I have two tables in my database table1, table2. I have a join query
Suppose I have two tables on a database, T 10 and T 11 ,
Imagine we have two tables in the database, user (FK id_role) and role (PK
I have two tables in my MySQL database, one is a library of all

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.