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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:05:31+00:00 2026-06-04T06:05:31+00:00

I’m trying to SELECT, and get a unique result set, from a MySQL database,

  • 0

I’m trying to SELECT, and get a unique result set, from a MySQL database, as shown below. My problem is, I think, I don’t understand LEFT Joins well enough. Or, maybe I need to use a different Join approach.

Here’s a description of the database.

tbAdult (Adults) have x number of tbchild (Children) , and uses a cross-ref table called tbadultchildxref. This table has an f-key to both Adult and Child. I have to use an x-ref table, because there’s a many-to-many relationship between these two tables, and there’s other data that’s keep in the x-ref, which I have removed for simplicity.

In turn, each Child belongs to a Program (tblprogram).

Each Program has x number of Cameras (tblCamera). Again, I have to use an x-ref table between tblProgram and tblCamera due to a many-to-many relationship, and other reasons.

What I am trying to get at, is a unique list of Cameras for a given Parent.

For example, Parent 675 has three children, Child ID’s 789,788, and 789. Those three children, in turn, belong to Program ID’s 4, 5, and 6.

Program ID 4 has Camera ID’s 1,2,3
Program ID 5 has Camera ID’s 4,5,6
Program ID 6 has Camera ID’s 1,6,7,8

What I would like the result set to be is 1,2,3,4,5,6,7,8

I have tried different combinations of SELECT DISTINCT, LEFT JOINS on the various x-ref tables, etc. but I just can’t seem to get it.

My other problem, along the way, is I need to check the “Active” fields in Adult, Child, and Program to equal = 1 (true) for the result set.

Thanks in advance.

CREATE TABLE `tbladult` (
 `pkAdultID` int(11) NOT NULL AUTO_INCREMENT,
 `fldAdultActive` tinyint(1) DEFAULT '1',
 `fldAdultLogin` varchar(30) DEFAULT NULL,
 `fldAdultPassword` varchar(45) DEFAULT NULL,
 `fldAdultFirstName` varchar(60) DEFAULT NULL,
 `fldAdultLastName` varchar(60) DEFAULT NULL,
 PRIMARY KEY (`pkAdultID`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;


/*Table structure for table `tblchild` */

CREATE TABLE `tblchild` (
 `pkChildID` int(11) NOT NULL AUTO_INCREMENT,
 `fldChildActive` tinyint(4) DEFAULT NULL,
 `fldChildFirstName` varchar(45) DEFAULT NULL,
 `fldChildLastName` varchar(45) DEFAULT NULL,
 `fkChildProgram` int(1) DEFAULT NULL,
 PRIMARY KEY (`pkChildID`),
 KEY `FK_tblchild` (`fkChildProgram`),
 CONSTRAINT `FK_tblchild` FOREIGN KEY (`fkChildProgram`) REFERENCES `tblprogram` (`pkProgramID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;


/*Table structure for table `tbladultchildxref` */

CREATE TABLE `tbladultchildxref` (
 `pkAdultChildxRefID` int(11) NOT NULL AUTO_INCREMENT,
 `fldAdultChildxRefActive` tinyint(1) DEFAULT '1',
 `fkAdultID` int(11) DEFAULT NULL,
 `fkChildID` int(11) DEFAULT NULL,
 PRIMARY KEY (`pkAdultChildxRefID`),
 KEY `FK_tbladultchildxref` (`fkAdultID`),
 KEY `FK_tbladultchildxref2` (`fkChildID`),
 CONSTRAINT `FK_tbladultchildxref` FOREIGN KEY (`fkAdultID`) REFERENCES `tbladult` (`pkAdultID`),
 CONSTRAINT `FK_tbladultchildxref2` FOREIGN KEY (`fkChildID`) REFERENCES `tblchild` (`pkChildID`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;



/*Table structure for table `tblprogram` */

CREATE TABLE `tblprogram` (
  `pkProgramID` int(11) NOT NULL AUTO_INCREMENT,
  `fldProgamActive` tinyint(1) DEFAULT '1',
  `fldProgramName` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`pkProgramID`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;

/*Table structure for table `tblcamera` */

CREATE TABLE `tblcamera` (
 `pkCameraID` int(11) NOT NULL AUTO_INCREMENT,
 `fldCameraName` varchar(50) DEFAULT NULL,
 `fldCameralocation` varchar(50) DEFAULT NULL,
 `fldCameraURL` varchar(250) DEFAULT NULL,
 PRIMARY KEY (`pkCameraID`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;


/*Table structure for table `tblprogramcameraxref` */

CREATE TABLE `tblprogramcameraxref` (
 `pkProgramCameraXrefID` int(11) NOT NULL AUTO_INCREMENT,
 `fkProgramID` int(11) DEFAULT NULL,
 `fkCameraID` int(11) DEFAULT NULL,
 PRIMARY KEY (`pkProgramCameraXrefID`),
 KEY `FK_tblprogramcameraxref` (`fkProgramID`),
 KEY `FK_camerasforprograms` (`fkCameraID`),
 CONSTRAINT `FK_camerasforprograms` FOREIGN KEY (`fkCameraID`) REFERENCES `tblcamera`     (`pkCameraID`),
 CONSTRAINT `FK_tblprogramcameraxref` FOREIGN KEY (`fkProgramID`) REFERENCES `tblprogram` (`pkProgramID`)
  • 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-04T06:05:33+00:00Added an answer on June 4, 2026 at 6:05 am

    No LEFT JOINs necessary:

    SELECT DISTINCT tblprogramcameraxref.fkcameraid
    FROM tblprogramcameraxref
    JOIN tblprogram ON tblprogramcameraxref.fkprogramid = tblprogram.pkprogramid
      AND tblprobram.fldProgramActive = 1
    JOIN tblchild ON tblprogramcameraxref.fkprogramid = tblchild.fkchildprogram 
      AND tblchild.fldChildActive = 1
    JOIN tbladultchildxref ON tblchild.pkchildid = tbladultchildxref.fkchildid
      AND tbladultchildxref.fldAdultChildxRefActive = 1
    WHERE tbladultchildxref.fkadultid = 675
    

    Also, you may want to check the fkChildProgram int(1) DEFAULT NULL, in tblchild – the column it references is defined as int(11)

    At this point you shouldn’t really need to check if Adult is active (since that’s the search criteria you started with), but if you must – just add this to the end of the join list:

    JOIN tbladult ON tbladultchildxref.fkadultid = tbladult.pkadultid
      AND tbladult.fldAdultActive = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.