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

  • Home
  • SEARCH
  • 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 6761629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:12:55+00:00 2026-05-26T14:12:55+00:00

I have been trying to build an SQL query to return matches between three

  • 0

I have been trying to build an SQL query to return matches between three tables.

SELECT DISTINCT thing.ip, thing.mac, 
    thing.vlan, thing.port 
FROM device 
INNER JOIN thing ON device.ip=thing.switch 
INNER JOIN portdetail ON device.ip=portdeail.poll_ip 
WHERE device.id="abc"

It originally worked perfectly until I added the second INNER JOIN, this resulted in no end of duplicate results. I then included the distinct keyword and it suddenly returned to normal again.
As soon as I add in a field from the third table to the first select statement it goes back to showing many duplicates again. (portdetail.name).

I have found questions regarding this which have been solved by using the distinct keyword or by refining the ON selection. None of these appear to have helped (or at least they did until the addition of that last field)

SELECT DISTINCT thing.ip, thing.mac, 
    thing.vlan, thing.port, portdetail.name
FROM device 
INNER JOIN thing ON device.ip=thing.switch 
INNER JOIN portdetail ON device.ip=portdeail.poll_ip 
WHERE device.id="abc"

It is operating on an SQLite 3 database.

EDIT:

To clarify. device lists devices such as switches. I then want to take the IP of a switch (device.ip and find some details on it from the thing table. The thing table being a table containing detail on the switches.

Now the portdetail table holds the name of the interfaces (Fa0/1, Fa0/2 etc) against the portdetail.poll_ip which is the IP of the switch, so I want to pull all interface names for a particular switch. I hope that is slightly clearer (I didn’t name the database tables and have no power to change them at this stage)

  • 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-26T14:12:56+00:00Added an answer on May 26, 2026 at 2:12 pm

    Ok, so thanks to a clever bod in an IRC channel they suggested adding a second WHERE clause as at present I was only identifying from one table.
    Once I added a couple of extra WHERE clauses to identify fields between tables it all worked perfectly. (E.g. WHERE TABLE.FIELD == TABLE2.OTHERFIELD)
    Thanks for the suggestions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got a live update twitter thing that i have been trying to build,
I have been trying to explain the difference between switch statements and pattern matching(F#)
I've been trying to construct a sql query with ZendFW, but I cant seem
I'm trying to build a Hibernate Criteria query to find entities that have a
I have been trying to build only the /libcore directory of the Android platform.
I am trying to build the following query: `new Select(GTekst = ArrGruppe.Tekst, GLTekst =
I have been trying to build a custom uitableview swipe. I am successful in
I have been trying to build a modular web application. My requirements are to
As an exercise, I have been trying to build a non-GUI boggle type game
Background I have a personal project that I've been trying to build for around

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.