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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:16:05+00:00 2026-05-29T08:16:05+00:00

Sorry, guys.I am quite new in mysql but I do need help from getting

  • 0

Sorry, guys.I am quite new in mysql but I do need help from getting and merging data from 2 tables.

table_a

ID | TITLE | CONTENT | DATE

table_b

ID | POST_ID | IMAGE

Here’s my code

$query = "SELECT table_a.*, table_b.IMAGE FROM table_a
LEFT JOIN table_b
      ON table_a.ID = table_b.POST_ID
      ORDER BY table_a.DATE";
$mysql_result = mysql_query($query);

$result = array();
while ($row = mysql_fetch_assoc($mysql_result)) {
   $result[] = $row;
}
print json_encode($result);

However, for those record in table_a which got more than 1 IMAGE, my json contain duplicated CONTENT with different IMAGES.

Is there any methods to merge IMAGE with the same ID into a single record?

Thanks for any helps!

  • 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-05-29T08:16:05+00:00Added an answer on May 29, 2026 at 8:16 am

    If I understand correctly, you want to have all fields from table_a, and only one (maybe combined) field from table_b.

    First of all, you have to decide what you want to get, if you have more than one image:

    • Only 1 image? Use MIN(table_b.IMAGE) or MAX(table_b.IMAGE) in the
      following SQL
    • All images separated by e.g. a comma? Use GROUP_CONCAT(table_b.IMAGE SEPARATOR ',') or similar in the following SQL

    Next you have to understand, that to get only one row per table_a.ID, you have to group by table_a.ID, so we have

    SELECT
      table_a.*,
      <function from above> AS image
    FROM  table_a
    LEFT JOIN table_b
          ON table_a.ID = table_b.POST_ID
    GROUP BY table_a.ID
    ORDER BY table_a.DATE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry guys for noob question, need help. I'm try to use Sharekit - https://github.com/ShareKit/ShareKit
Sorry guys , need to bring my old question back from the dead as
Sorry guys if this is a noob question. I need help on how to
Hello guys sorry if the question looks stupid to you. i have 3 tables
guys sorry for being so noob but im still starting yet with my php,
Sorry for the wall of text guys but this one requires expliaining, way too
Ok guys, I'm really new at python (and programming itself) so sorry for my
Sorry guys, I'm a noob. I know that some languages support type casting, but
Sorry guys, I hate asking dumb questions but I have seriously been searching for
Possible Duplicate: Difference between single quotes and double quotes in Javascript Sorry guys, but

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.