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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:17:29+00:00 2026-06-18T09:17:29+00:00

DB: PostgreSQL Suppose I have table A(integer a_id, timestamp x, timestamp y) table B(int

  • 0

DB: PostgreSQL

Suppose I have

table A(integer a_id, timestamp x, timestamp y) 
table B(int b_id, timestamp n, timestamp m)

m can be null

I want to fetch the data with this structure

SELECT a_id, j.b_id, k.b_id 
FROM A, B AS j, B AS k 
WHERE (x BETWEEN j.n AND j.m) AND (y BETWEEN k.n AND k.m.)

When (x BETWEEN j.n AND j.m) AND (y BETWEEN k.n AND k.m.)‘s matches aren’t not found

I still want the query to fetch the data with null j.b_id or null k.b_id

How do I do that?

  • 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-18T09:17:30+00:00Added an answer on June 18, 2026 at 9:17 am

    My interpretation of the cryptic question …

    SELECT a_id, j.b_id, k.b_id 
    FROM   a
    LEFT   JOIN b j ON a.x BETWEEN j.n AND j.m
    LEFT   JOIN b k ON a.y BETWEEN k.n AND k.m
    

    If no matching row is found in j or k, NULL is delivered for j.b_id or k.b_id respectively.

    The query suffers from the principal design flaw that multiple matches in b will multiply the number of rows returned in a CROSS JOIN fashion.

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

Sidebar

Related Questions

Suppose I have this foo table in a PostgreSQL 9.1 database: CREATE TABLE foo
In my Postgresql database, I have a timestamp without time zone with this value
In PostgreSQL I have a table with a varchar column. The data is supposed
Suppose we have a PostgreSQL database with two tables A, B. table A columns:
I am new to PostgreSQL. Suppose I have a table as under colorname Hexa
Suppose I have a big table in PostgreSQL (more than 500Gb) - work pool.
Suppose you have two tables in PostgreSQL. Table A has field x , which
In PostgreSQL 8.3, let's say I have a table called widgets with the following:
Suppose I have two queries on a database table. The queries are defined in
I have a postgres table like this: CREATE SEQUENCE seq; CREATE TABLE tbl (id

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.