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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:29:43+00:00 2026-05-20T15:29:43+00:00

I have two tables: projects and user_licenses . I’d like to grab the entire

  • 0

I have two tables: projects and user_licenses.

I’d like to grab the entire list of projects from the database, as well as the user’s current license state. The licenses table has a user ID field which I check against a $_SESSION variable for the value. The thing is, they might not have a license, or a non-logged in visitor may want to see the projects list. My question is this: How can I get the data from the left table always display, but only grab data for that row from the right table when certain conditions are met?

The query I have at the moment is this:

   SELECT Projects.*, 
          UserLicenses.* 
     FROM Projects 
LEFT JOIN UserLicenses ON Projects.id = UserLicenses.project_id 
    WHERE UserLicenses.user_id = 12 
 ORDER BY name ASC
  • 1 1 Answer
  • 3 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-20T15:29:44+00:00Added an answer on May 20, 2026 at 3:29 pm

    Add any extra conditions to the on clause of the left join. They will only affect the joined table.

      SELECT Projects.*, 
              UserLicenses.* 
         FROM Projects 
    LEFT JOIN UserLicenses 
           ON Projects.id = UserLicenses.project_id 
              and UserLicenses.user_id = 12 
              and UserLicences.Question = '6*7'
              and UserLicences.Answer = 42
     ORDER BY name ASC
    

    This will return projects without matching licenses.

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

Sidebar

Related Questions

I have two tables: projects and tasks. A project consists of tasks. I want
I have two tables: one called Projects, and another called Documents (projects has many
I have two tables: 1. tableA is a list of records with many columns.
I have two tables, one is a list of songs. The other is a
Have two mysql databases in two servers, I have to share user information tables
I have a database that has two tables, one of which contains a foreign
I have two tables. Table A: Contains a list of songs, song artwork, mp3
I have two tables with a many-to-many relation with a bridge table. User Class
I have very simple form along with two database tables. In this form is
I've have two tables in my project which are User and InvoiceLine. It has

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.