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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:07:57+00:00 2026-05-27T15:07:57+00:00

I’m having trouble doing the following in SQL with Postgres. My program has an

  • 0

I’m having trouble doing the following in SQL with Postgres. My program has an ordered set of numbers. In my database I have the table which stores all numbers in rows with extra data. These rows are also placed in order.

For example my set I need to find is;

1,5,6,1,3

The database has rows

row1 4
row2 5
row3 1
row4 5
row5 6
row6 1
row7 3
row8 2
row9 7

In the example above it’s easy to see that my set is found from row 3 to to row7. Still doing such in SQL is a mystery to me. I’m reading some articles regarding pivot tables, still I’m hoping there’s an easier way.

  • 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-27T15:07:58+00:00Added an answer on May 27, 2026 at 3:07 pm

    Both data-sets need to have fields that identify the order.

    And provided that the ordering column is a sequential consecutive set of numbers, then this is possible, although I doubt it’s very quick.

    Table 1                 Table 2
    
    id | value              id | value
     1    4                  1    1
     2    5                  2    5
     3    1                  3    6
     4    5                  4    1
     5    6                  5    3
     6    1                  
     7    3                  
     8    2                  
     9    7                  
    

    Then this query…

    SELECT
      *
    FROM
      table_1
    INNER JOIN
      (
        SELECT
          MIN(table_1.id)    AS first_id,
          MAX(table_1.id)    AS last_id
        FROM
          table_1
        INNER JOIN
          table_2
            ON table_1.value = table_2.value
        GROUP BY
          table_1.id - table_2.id
        HAVING
          COUNT(*) = (SELECT COUNT(*) FROM table_2)
      )
      AS matched_sets
        ON  matched_sets.first <= table_1.id
        AND matched_sets.last  >= table_1.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a reasonable size flat file database of text documents mostly saved in
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has

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.