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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:36:42+00:00 2026-06-13T14:36:42+00:00

I have a table Information which is something like this: ID From To Product

  • 0

I have a table Information which is something like this:

ID    From     To        Product          Date  
1         A         B          ProdA         2012-10-01  
2         A         B          ProdA         2012-10-13  
3         A         B          ProdB         2012-10-17  
4         A         B          ProdC         2012-10-18  
5         A         C          ProdB         2012-10-02  
6         A         C          ProdC         2012-10-04  
7         A         C          ProdD         2012-10-12  
8         A         C          ProdE         2012-10-14  
9         A         D          ProdA         2012-10-11  
10       A         D          ProdA         2012-10-14  

Let’s call the combination of From and To a relationship. So (A,B) and (A, C) are relationships.
What I need to do is to find those relationships sending/receiving different products within a week time period. So in the above example the query is supposed to return:

A    B
A    C

since these rows match:

2         A         B          ProdA         2012-10-13  
3         A         B          ProdB         2012-10-17  
4         A         B          ProdC         2012-10-18  

5         A         C          ProdB         2012-10-02  
6         A         C          ProdC         2012-10-04  

7         A         C          ProdD         2012-10-12  
8         A         C          ProdE         2012-10-14  

I know I should start from SELECT ID, From, To, Product, Date FROM Information GROUP BY From, To but I have no idea what’s next. Any help please?

  • 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-13T14:36:44+00:00Added an answer on June 13, 2026 at 2:36 pm

    something like this perhaps:

    declare @t table(id int identity(1,1), [from] char default 'A', [to] char, product char(5), date date)
    -- populating testdata works with sql server 2008+
    insert @t ([to],product, date) values
    ('B','ProdA','2012-10-01'),('B','ProdA','2012-10-13'),
    ('B','ProdB','2012-10-17'),('B','ProdC','2012-10-18'),
    ('C','ProdB','2012-10-02'),('C','ProdC','2012-10-04'),
    ('C','ProdD','2012-10-12'),('C','ProdE','2012-10-14'),
    ('D','ProdA','2012-10-11'),('D','ProdA','2012-10-14')
    
    
    select * from @t t where exists 
    (select 1 from @t where t.[from] = [from] and t.[to] = [to] and 
    t.product <> product and t.date between dateadd(day, -7, date) and 
    dateadd(day, 7, date))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of product information with many bit columns. This table can
I have a table which looks like this: CREATE TABLE `library_mix` ( `lib_mix_id` VARCHAR(64)
Greetings friends, In my MySQL database, I have 'MAB' table which contains information about
I have a products table which contains information about products. Each products can have
I have a table in which users store scores and other information about said
I have a table called restaurants which contains each restaurant information, I want to
Say I have a table called Users, which contains your typical information: Id, Name,
I currently have a table called paper , which holds all the information for
I have table View with grouped style with three sections. Get information from dictionary
I have a table in Oracle 10 that is defined like this: LOCATION HOUR

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.