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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:17:22+00:00 2026-06-12T22:17:22+00:00

I have got 2 Tables I need to query. I cannot unique values for

  • 0

I have got 2 Tables I need to query. I cannot unique values for the linked key.
The first Table stores stories or posts per child.

CREATE TABLE IF NOT EXISTS `learning_story` (
  `story_id` int(10) NOT NULL AUTO_INCREMENT,
  `child_id` int(10) NOT NULL,
  `img_file` varchar(250) NOT NULL,
  `title` varchar(300) NOT NULL,
  `description` text NOT NULL,
  `link` varchar(300) NOT NULL,
  `storydate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `teacher_id` int(11) NOT NULL,
  `pro_id` int(10) NOT NULL DEFAULT '0',
  `status` varchar(10) NOT NULL DEFAULT 'draft',
  PRIMARY KEY (`story_id`),
  KEY `child_id` (`child_id`),
  KEY `pro_id` (`pro_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;

Each story or post is unique to a child (child_id Foreign Key).
Now I am adding the ability to add posts that belong to a group of children.
Here are 4 sample rows

INSERT INTO `learning_story` (`story_id`, `child_id`, `img_file`, `title`, `description`, `link`, `storydate`, `teacher_id`, `pro_id`, `status`) VALUES
(1, 5, '', 'Story 1', '<p><img src="http://127.0.0.1/websites/my-books/assets/mercury_img/2dfeb1f41c48a308b7eee8526918ebb7.JPG" style="cursor: default; width: 222.28915662650604px; height: 125px; float: right; margin: 0px 0px 10px 10px; " alt=""></p><p><img src="http://127.0.0.1/websites/my-books/img/timbthumb.php?src=http://127.0.0.1/websites/my-books/assets/2/children/test_09.JPG&q=100&w=180&h=130" alt="imagetitle" style="cursor: default; ">dsd sdsdsd s ds ffdfdf </p>\r\n', '', '2012-10-08 20:42:05', 0, 2, 'draft'),
(12, 5, '', 'Teachers Final Test 33', '<p>ds sd sd sd sd  dsdsd dsd sd s </p><p><br></p><p>Tweety</p>\r\n', '', '2012-10-12 12:19:45', 31, 2, 'draft'),
(30, 6, '', 'Boys High Choir', '<p>sasassa</p>', '', '2012-10-14 09:55:08', 0, 2, 'draft'),
(32, 0, '', 'Story Not Mine ID 5', '<p>dsd sd sd s ds ds ds sd sd </p>\r\n', '', '2012-10-14 12:21:36', 0, 2, 'draft');

Among these there is 1 record that has a child_id set to 0. This record belongs to the child_id’s in the 2nd table.

2nd table

CREATE TABLE IF NOT EXISTS `story_groups` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `child_id` int(10) NOT NULL,
  `story_id` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=112 ;



INSERT INTO `story_groups` (`id`, `child_id`, `story_id`) VALUES
(40, 7, 30),
(41, 8, 30),
(107, 8, 32),
(108, 9, 32),
(109, 11, 32),
(110, 12, 32),
(111, 5, 32);

So I want to get all stories/posts for a child. Including the Group Stories.

I have tried UNION matching and a bunch of JOIN combinations but I just cant crack it.

It is probably a simple JOIN operation which I just cant crack.

Could somebody please help me write my query to include the rows from the story_groups table?

  • 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-12T22:17:23+00:00Added an answer on June 12, 2026 at 10:17 pm
    SELECT learning_story.*
    FROM   learning_story LEFT JOIN story_groups USING (story_id)
    WHERE  learning_story.child_id = ? OR story_groups.child_id = ?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables linked by a foreign key. Example: CREATE TABLE one (id
I've got three tables: CREATE TABLE credential_types ( id serial PRIMARY KEY, name varchar(32)
I have 3 tables and need to select some recoreds, In 2 table of
I've got three tables posts tags posts_tags I need to write some controller logic
I've got two un-related (no FK's defined) tables. The first table contains some tasks
Ive got a problem with a MySQL query. Let's say, we have two tables:
I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
I have got a few tables which I am trying to join. I just
I am trying to empty the tables but I was wondering have I got
I've got the following tables: magazine_tags news_tags page_tags content_tags faq_tags They all have exactly

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.