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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:41:02+00:00 2026-05-19T23:41:02+00:00

I am trying to get data from three different tables at once, and I

  • 0

I am trying to get data from three different tables at once, and I don’t think I quite understand joins correctly, as I’m getting nowhere fast.
For example, lets say the tables are houses, sellers, and selling_details. houses and sellers are linked by the selling_details: it has a seller_id and a house_id, plus more information such as price, and a link to a user.

I want to build a query that returns all houses in the system, matched up to all sellers, and list the selling details if present. For example:

+------------+-------------+-------------------------+----------------------+-----------+
| house.name | seller.name | selling_details.details | selling_details.date | user.name |
+------------+-------------+-------------------------+----------------------+-----------+
| One        | One         | details                 | 2011-02-18           | bobby     |
| One        | Two         | details                 | 2011-02-24           | frank     |
| One        | Three       | NULL                    | NULL                 | NULL      |
| One        | Four        | NULL                    | NULL                 | NULL      |
| Two        | One         | details                 | 2011-01-16           | ned       |
| Two        | Two         | NULL                    | NULL                 | NULL      |
| Two        | Three       | details                 | 2011-02-12           | will      |
| Two        | Four        | NULL                    | NULL                 | NULL      |
+------------+-------------+-------------------------+----------------------+-----------+

What would be the easiest way to go about this?

Edit: It seems I’m trying to oversimplify the problem so here’s some more detail:

Here’s a fraction of the schema I’m using:

create table `house` (`id` int not null auto_increment, `name` varchar(255) null, primary key (`id`))
create table `seller` (`id` int not null auto_increment, `name` varchar(255) null, primary key (`id`))
create table `user` (`id` int not null auto_increment, `name` varchar(255) null, primary key (`id`))
create table `selling_details` (`id` int not null auto_increment, `details` varchar(255) not null, date datetime not null, `house_id` int null, `seller_id` int null, `user_id` int not null, primary key (`id`))

alter table `selling_details` add index `FK_selling_details_user` (`user_id`), add constraint `FK_selling_details_user` foreign key (`user_id`) references `user` (`id`)
alter table `selling_details` add index `FK_selling_details_house` (`house_id`), add constraint `FK_selling_details_house` foreign key (`house_id`) references `house` (`id`)
alter table `selling_details` add index `FK_selling_details_seller` (`seller_id`), add constraint `FK_selling_details_seller` foreign key (`seller_id`) references `seller` (`id`)

Now, just to make things really complicated too, there may be many rows in the selling_details table linking house and seller. If there is one or more of these rows present, I only want the one with the most recent date; if there’s no such row, still return the house and seller combination as in the example results above.

  • 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-19T23:41:03+00:00Added an answer on May 19, 2026 at 11:41 pm

    Cross join the house and sellers, then left join to find any details for the combination

    select h.house_id, s.seller_id, sd.details
    from houses h
    cross join sellers s
    left join selling_details sd
        on sd.seller_id = s.seller_id
        and sd.house_id = h.house_id
    order by h.house_id, s.seller_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out a clean way of getting data back from my
I am trying to scrape the datas from a webpage, but I get need
I'm trying to get a directory listing of files on an ftp server using
I am trying to pass data between two pages using Session State in ASP.NET.
I'm trying to project parts of a Display and its list of locations from
This seems like it should be so easy, but I've tried three or four
I have written a code in Python to create a transition probability matrix from
I have a database which has a table with an XML column. The XML
I'm a newbie with WPF and c# and have a (probably very simple) problem.
I have not really worked with datasets before. I use a lot of LINQ

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.