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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:52:10+00:00 2026-06-04T19:52:10+00:00

So, I have this MySQL problem. I’ve been looking at LEFT JOIN, INNER JOIN

  • 0

So, I have this MySQL problem.

I’ve been looking at LEFT JOIN, INNER JOIN etc. And as I understand LEFT JOIN joins from left and if the right part doesn’t exist it’s values get set to NULL. And with INNER JOIN if there is no match for the join, an empty set is returned.

As you can see from my previous statement I join different statistics and such for one of the users in the match. But if uid2 isnt friend with uid1 this will give null in my case for all fields in friends.*

How would I do to get all the friends fields if they are friends and no fields from friends if they arent. (I dont want to do a separate statement before to check if they’re friends).

This is my previous statemenet:

SELECT matches.*, statistics.*, friends.*, users.username
FROM `matches`
LEFT JOIN statistics ON matches.uid1=statistics.uid
LEFT JOIN users ON matches.uid1=users.uid
LEFT JOIN friends ON matches.uid1=friends.fid AND matches.uid2=friends.uid
WHERE matches.mid IN (269,231,131)
  • 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-04T19:52:12+00:00Added an answer on June 4, 2026 at 7:52 pm

    Then you just replace the last LEFT JOIN with an INNER JOIN:

    SELECT matches.*, statistics.*, friends.*, users.username
    FROM `matches`
    LEFT JOIN statistics ON matches.uid1=statistics.uid
    LEFT JOIN users ON matches.uid1=users.uid
    INNER JOIN friends ON matches.uid1=friends.fid AND matches.uid2=friends.uid
    WHERE matches.mid IN (269,231,131);
    

    However, it’s not possible to selectively not return the columns from the friends table when they can’t be joined.

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

Sidebar

Related Questions

I have this mysql tables I want to display with jqgrid. The problem appears
hello all this seems to be my problem I have a table in mysql
I'm not a MySQL expert and am having problem with this... So, I have
i have this MySQL statement from a search page, the user enters there postcode
So, I have this mysql query: SELECT member_id, text FROM review WHERE text !=
I have this intermittent problem with MySQL 5.1.33 (Community Server) for Windows, where the
I have a problem constructing a mysql query: I have this table tSubscribers were
I have a mysql problem. I have two tables like this that I need
I have this MySql query: SELECT YEAR(date), MONTHNAME(date), SUM(block_time) FROM flights WHERE operator =
I have this problem with saving a date into a MySQL database. I have

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.