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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:09:43+00:00 2026-06-12T03:09:43+00:00

table1 house_id|house_name|status 1 | A | 1 2 | B | 1 3 |

  • 0

table1

house_id|house_name|status

  1     |     A    |  1
  2     |     B    |  1
  3     |     C    |  0
  4     |     D    |  1
  5     |     E    |  1
  6     |     F    |  1

table1

house_id| image

   2    | img1.jpg
   2    | img2.jpg
   1    | img3.jpg
   4    | img4.jpg
   1    | img5.jpg
   4    | img6.jpg
   3    | img7.jpg

I want select all house_id from table1 where status =1 (descending) , select distinct image from table2, for each house_id of table1 .

Finally output show bellow :

Output

house_id|house_name|image

   6    |    F     |NULL
   5    |    E     |NULL
   4    |    D     |img4.jpg
   2    |    B     |img1.jpg  
   1    |    A     |img3.jpg  

please help me code with normal mysql or CI active record class method ..

  • 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-12T03:09:44+00:00Added an answer on June 12, 2026 at 3:09 am

    try this out….(normal mysql)

    SELECT t1.*,t2.image FROM table1  t1
    LEFT JOIN table2 t2 on t1.house_id=t2.house_id
    WHERE t1.status= 1 GROUP BY t1.house_id ORDER BY house_id desc
    

    active record…

    $this->db->select(t1.*,t2.image);
    $this->db->from('table1'.' t1');
    $this->db->join('table2'.' t2','t1.house_id=t2.house_id','left');
    $this->db->where('t1.status',1);
    $this->db->group_by("t1.house_id"); 
    $this->db->order_by("house_id");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

table1 is the parent table with a column ID and table2 has a column
Table1: id - name 1 - john 2 - david 3 - dilio Table2:
Table1 Time 10:00:00 12:00:00 Absent 14:00:00 Holiday ..., Time column Datatype is varchar I
Table1 ID product 001 LG 001 Sony 001 LG 001 LG 001 Sony 001
Table1 ID | WorkTime ----------------- 001 | 10:50:00 001 | 00:00:00 002 | ....
Table1 Date id salary 01/2012 001 1500 01/2011 001 750 01/2010 001 500 from
Table1: ResourceID Name0 (STRING) NumberOfLongons0 (INT) LastLogon0 (DateTIME) Table2: ResourceID NetbiosName0 I am trying
Table1 ID Loc ----------- 001 null 002 null 003 PYD 004 null .... Table2
I want to develop a DB structure where every object will go in its
I have a query to randomly select 6 images from 3 SQL tables in

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.