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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:57:23+00:00 2026-06-16T20:57:23+00:00

I have two tables like that: summary(id, status, value, time, aperson) and long_summary(id, who,

  • 0

I have two tables like that:

summary(id, status, value, time, aperson) and long_summary(id, who, comment, alltext)

for that i have tried with below query like:

SELECT l.id,summary.status
FROM  long_summary l INNER JOIN summary ON l.id = summary.id INNER JOIN long_summary ON summary.aperson = long_summary.who 
WHERE summary.status IN('old','new','waiting')
AND summary.value IN ('') 
AND summary.time >= DATE_SUB(NOW(),INTERVAL 2 MONTH)
AND l.alltext LIKE '% relational database management system %' ORDER BY FIELD(summary.status,'old','new','waiting'),summary.time DESC

While running it is giving correct output but retured rows are comming multiple times like:

(1,'old')
(1,'old')
(1,'old')
(2,'new')
(2,'new')
(3,'new')
(4,'waiting')
(4,'waiting')

For that i have used SELECT DISTINCT and after that it is giving correct output without repetition of the single row. But i am not getting what i have done wrong?
Will you please suggest?

  • 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-16T20:57:24+00:00Added an answer on June 16, 2026 at 8:57 pm

    The way to see what’s happening is to (a) create a stripped-down test case, and (b) do a SELECT * so you can see what you’re getting back in the other columns, that’s causing the repetition.

    So, I did this:

    CREATE TABLE summary(id, status, value, time, aperson);
    INSERT INTO "summary" VALUES(1,'old',23,'time0','joe');
    INSERT INTO "summary" VALUES(2,'new',42,'time1','bob');
    INSERT INTO "summary" VALUES(3,'new',32,'time2','mike');
    CREATE TABLE long_summary(id, who, comment, alltext);
    INSERT INTO "long_summary" VALUES(1,'someone','i say!','some text');
    INSERT INTO "long_summary" VALUES(1,'joe','joe likes','some text');
    INSERT INTO "long_summary" VALUES(2,'joe','joe likes bob','some text');
    INSERT INTO "long_summary" VALUES(3,'joe','joe likes mike','some text');
    INSERT INTO "long_summary" VALUES(1,'bob','nice one, joe','some text');
    INSERT INTO "long_summary" VALUES(2,'bob','nice one, me','some text');
    INSERT INTO "long_summary" VALUES(2,'bob','double nice one, me','some text');
    INSERT INTO "long_summary" VALUES(3,'bob','nice one, mike','some text');
    COMMIT;
    

    Then I took a simpler version of your query:

    SELECT l.id,summary.status
    FROM  long_summary l INNER JOIN summary ON l.id = summary.id INNER JOIN long_summary ON summary.aperson = long_summary.who 
    WHERE summary.status IN('old','new','waiting')
    

    None of the other stuff could make things any worse, right? So it’s irrelevant. What do I get when I run this? 9 copies of 1|old, and 12 copies of 2|new.

    So, let’s change it to see the whole row:

    SELECT *
    FROM  long_summary l INNER JOIN summary ON l.id = summary.id INNER JOIN long_summary ON summary.aperson = long_summary.who 
    WHERE summary.status IN('old','new','waiting')
    
    1|bob|nice one, joe|some text|1|old|23|time0|joe|1|joe|joe likes|some text
    1|bob|nice one, joe|some text|1|old|23|time0|joe|2|joe|joe likes bob|some text
    1|bob|nice one, joe|some text|1|old|23|time0|joe|3|joe|joe likes mike|some text
    1|joe|joe likes|some text|1|old|23|time0|joe|1|joe|joe likes|some text
    1|joe|joe likes|some text|1|old|23|time0|joe|2|joe|joe likes bob|some text
    1|joe|joe likes|some text|1|old|23|time0|joe|3|joe|joe likes mike|some text
    1|someone|i say!|some text|1|old|23|time0|joe|1|joe|joe likes|some text
    1|someone|i say!|some text|1|old|23|time0|joe|2|joe|joe likes bob|some text
    1|someone|i say!|some text|1|old|23|time0|joe|3|joe|joe likes mike|some text
    2|bob|double nice one, me|some text|2|new|42|time1|bob|1|bob|nice one, joe|some text
    2|bob|double nice one, me|some text|2|new|42|time1|bob|2|bob|double nice one, me|some text
    2|bob|double nice one, me|some text|2|new|42|time1|bob|2|bob|nice one, me|some text
    2|bob|double nice one, me|some text|2|new|42|time1|bob|3|bob|nice one, mike|some text
    2|bob|nice one, me|some text|2|new|42|time1|bob|1|bob|nice one, joe|some text
    2|bob|nice one, me|some text|2|new|42|time1|bob|2|bob|double nice one, me|some text
    2|bob|nice one, me|some text|2|new|42|time1|bob|2|bob|nice one, me|some text
    2|bob|nice one, me|some text|2|new|42|time1|bob|3|bob|nice one, mike|some text
    2|joe|joe likes bob|some text|2|new|42|time1|bob|1|bob|nice one, joe|some text
    2|joe|joe likes bob|some text|2|new|42|time1|bob|2|bob|double nice one, me|some text
    2|joe|joe likes bob|some text|2|new|42|time1|bob|2|bob|nice one, me|some text
    2|joe|joe likes bob|some text|2|new|42|time1|bob|3|bob|nice one, mike|some text
    

    OK, now you can see the problem, let’s see why it’s happening. Is each of these rows supposed to be there? In other words, should you see a 1|old if at least one of the first three combinations are there?

    If not, which ones shouldn’t be causing it? You need to filter something out in either the WHERE or the JOIN.

    If so, then you need a GROUP BY to merge together the relevant fields, or an OR somewhere, more likely the first.

    Step through all of the groups asking the same question. If you get to the point where you need a GROUP BY on the columns you’re actually displaying, it’s simpler to just use a SELECT DISTINCT.

    You also might want to step back and ask whether you really want a full JOIN of long_summary with summary with long_summary. That’s 8*3*8=192 rows that you’ve filtered down to 21. Does that make sense, or did you only expect, say, 24 rows to filter down? If the latter, you’ve got the JOIN wrong. Either one of those JOINs shouldn’t be there at all, or it should be a one-to-one instead of one-to-many JOIN, or something else is wrong with it.

    By the way, you might be able to tell from my test above that I used sqlite3 rather than mysql, just because it’s a lot simpler to get and running. I doubt that makes any difference, but if you test in mysql and see different results, by all means let me know.

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

Sidebar

Related Questions

I have two tables in my database that look like that: Customer: C_ID city
Let's say I have two tables that look like this: TH TH TH TH
I have two tables like of this structure: content (content_id, content_type, user_id, time, comment_count)
I have a mysql problem. I have two tables like this that I need
I have two tables that I would like to get data and from by
Say that I have two tables like those: Employers (id, name, .... , deptId).
I have two tables like so; id_image foo bar 1 3 5 2 8
I have two tables like, CREATE TABLE [dbo].[entry] ( [id] [int] NULL, [service] [int]
I have two tables like the ones below. I need to find what exchangeRate
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);

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.