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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:03:46+00:00 2026-06-09T18:03:46+00:00

I’m running MySQL 5.0.88 and need to select data from two tables, called articles

  • 0

I’m running MySQL 5.0.88 and need to select data from two tables, called articles and media.

When uploading images to my server I need to query all articles of a user and see whether there is already a path specified in the media table (field type="img") to avoid running unnecessary overwrites.

I had hoped to just include the m.type in my query, but I can’t get it to work.

My query looks like this:

SELECT DISTINCT a.style, a.filename, a.path, m.type
    FROM articles AS a
    LEFT JOIN mnedia AS m
       ON a.iln = m.iln
    WHERE
       a.iln = id_12345
       AND m.type = "img"
       AND m.type IS NOT NULL

This gives me ALL articles (correct) of user id_12345, but the type field is alway img although the media table only has one record for article abc.

Question:
How do I need to query, so it returns all articles of a user (working) displaying type=NULL for articles, which are NOT listed in table media and type="img" for articles, which are listed in the table media(such as abc)?

Thanks for help!

EDIT:
table articles may include records:

abc 
d
e
f
g

table media may include

abc type=img

the query should return:

abc type=img
d type=NULL
e type=NULL
f type=NULL
g type=NULL

EDIT:
I also woudn’t mind getting all records in articles that are not in media, such as on this image, 2nd join left hand side (“b.Key IS NULL)

SOLUTION:
Ok. I needed to check for another field besiders user_id when joining both tables. This is how it works:

SELECT DISTINCT a.style, a.filename, a.path, m.type
    FROM articles AS a
    LEFT JOIN mnedia AS m
       ON a.iln = m.iln
       AND a.style= m.style
    WHERE
       a.iln = id_12345
       AND ( m.type = "img" OR m.type IS NULL )

THANKS ALL for your suggestions!

  • 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-09T18:03:48+00:00Added an answer on June 9, 2026 at 6:03 pm

    you should put m.type = "img" condition on LEFT JOIN instead of putting it in WHERE clause:

    SELECT DISTINCT a.style, a.filename, a.path, m.type
    FROM articles AS a
         LEFT JOIN mnedia AS m
             ON a.iln = m.iln
                AND m.type = "img"
    WHERE a.iln = id_12345;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group

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.