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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:23:03+00:00 2026-05-23T19:23:03+00:00

I need help building a mysql query to select from multiple tables. I have

  • 0

I need help building a mysql query to select from multiple tables.
I have three database tables related to images: images, tags, tag_asc. I want to fetch an image data and its tag names by providing image_id.

For example, following is my tables structure:

images:

image_id    image_name     path       date   
1            test.jpg      dir       1311054433

tags:

tag_id      image_id
1             1
2             1

tag_asc:

tag_id      tag_name
1            "first"
2            "second"
3            "third"

I want to fetch the data of an image with image_id = 1 from images table and all tag names associated with image_id=1 from tag_asc table.

I’m using CodeIgniter Active records, but I just need idea of joining the tables.

Thanks for any help.

  • 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-23T19:23:04+00:00Added an answer on May 23, 2026 at 7:23 pm
    select *
    from images i
    left join tags t on t.image_id = i.image_id
    left join tag_asc ta on ta.tag_id = t.tag_id
    where i.image_id = 1;
    

    Using LEFT JOIN means that rows will be returned even if there are no joining rows in the other tables (but you’ll get null values in the columns for the missing rows), which is typically desirable.

    If you want one row (not stated in question, but in comments), use this:

    select i.image_id, group_concat(tag_name) as tag_names
    from images i
    left join tags t on t.image_id = i.image_id
    left join tag_asc ta on ta.tag_id = t.tag_id
    where i.image_id = 1
    group by 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with building SQL query. I have 4 tables: Sellers, Goods, Projects
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I have a problem with a quite slowish MYSQL query. I'm building an AJAX
I have a regex call that I need help with. I haven't posted my
I am newbie to db programming and need help with optimizing this query: Given
My apologies for asking such a novice question but, I need help building a
I am building an e-commerce website from scratch and have to make a special
I am building a facebook-like newsfeed and need help. We would like to start
i am building a chat room using php/mysql and jquery. I need to make
I need help building a loop in my stored procedure, basically i want it

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.