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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:32:05+00:00 2026-06-18T07:32:05+00:00

I have two tables in a mySQL database. milestones_all (PRIMARY KEY: MSID) user_transactions (FOREIGN

  • 0

I have two tables in a mySQL database.

  • milestones_all (PRIMARY KEY: MSID)
  • user_transactions (FOREIGN KEY: MSID)

I am using the following code to query the tables:

   $get_ms = db_query("SELECT * FROM milestones_all
        LEFT JOIN user_transactions on user_transactions.MSID = milestones_all.MSID 
        WHERE milestones_all.MID=$MID  
        AND (user_transactions.tran_status IS NULL OR user_transactions.tran_status=3)
        ORDER BY milestones_all.MSID ASC LIMIT 1"));

    while($ms = $get_ms->fetch_assoc()){
           $MSID = $ms['MSID'];
           $ms_title = $ms['ms_title'];
     }

Here is just the SQL:

SELECT * FROM milestones_all
LEFT JOIN user_transactions on user_transactions.MSID = milestones_all.MSID 
WHERE milestones_all.MID=$MID
AND (user_transactions.tran_status IS NULL OR user_transactions.tran_status=3)
ORDER BY milestones_all.MSID ASC LIMIT 1

What I am trying to do is print out the data from milestones_all for any row that either
doesn’t have a user_transactions row attached to it or, if it does, the column tran_status in user_transactions is set to 3.

As of now, the query returns the proper results regarding which rows to return. ms_title is returned exactly how is should be. The problem is: MSID always returns blank. It is not blank in my database. Could this be because the LEFT JOIN is using the MSID column to find matches? Maybe there is a totally better way to do this?

Note: the db_query function does not interfere.

  • 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-18T07:32:06+00:00Added an answer on June 18, 2026 at 7:32 am

    Yes, it’s because you have two columns named MSID. If you change the join to use USING instead of ON, it will collapse the two columns into one:

    SELECT * FROM milestones_all
    LEFT JOIN user_transactions USING(MSID) 
    WHERE milestones_all.MID=$MID
    AND (user_transactions.tran_status IS NULL OR user_transactions.tran_status=3)
    ORDER BY milestones_all.MSID ASC LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two tables in my mysql database. Table Name: groups id
Suppose I have the following two tables in my MySQL database: Table 1:: EMP:
I am using mysql database. I have two tables bugs and profiles. Bugs table
I'm using a MySQL database. I have two tables, Table 1 and Table 2.
I have a database using MySQL 2005. I have two tables, Enrolment and AlertMsg.
I have two tables in my MySQL database, one is a library of all
I have two tables in a MySql database: COUNTRY --------------- id, country_name and CITY
In a MySQL database I have two tables linked in a join. One table
What I have is two tables inside of a mysql database. One table contains
I am working on PHP and database MySQL. I have two tables in SQL

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.