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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:08:58+00:00 2026-06-02T21:08:58+00:00

The following two sentences: hello there bye! are represented in the table sentence_words by:

  • 0

The following two sentences:

hello there
bye!

are represented in the table sentence_words by:

WORD_ID  SENTENCE_ID    WORD    WORD_NUMBER
10       1              hello   1
11       1              there   2
12       2              bye!    1

I want to do an outer join query that gives me the results:

WORD1      WORD2
hello      there
bye!       NULL

Note that I may want to start in the middle of the sentence so I cannot assume that word2 has word_number = 2. If I choose my_start_number = 2 then the query should give me:

WORD1   WORD2
there   NULL

I tried:

(my_start_number = 1)

select  s1.word word1, s2.word word2
from sentence_words s1
left join sentence_words s2
on s1.sentence_id = s2.sentence_id
where s1.word_number = my_start_number
 and (s2.word_number = s1.word_number +1 or s2.word_number is null);

That only gives me a result if there are two words in the sentence. I’m not sure what to do that isn’t way complicated.

  • 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-02T21:09:00+00:00Added an answer on June 2, 2026 at 9:09 pm

    Move the word_number + 1 requirement into the LEFT JOIN.

    SELECT
      s1.word word1, s2.word word2
    FROM
      sentence_words s1
    LEFT JOIN
      sentence_words s2
        ON  s2.sentence_id = s1.sentence_id
        AND s2.word_number = s1.word_number + 1
    WHERE
      s1.word_number = my_start_number
    

    NECRO EDIT:

    Although the above fixes the use of LEFT JOIN, I would suggest not using joins at all…

    SELECT
      sentence_id,
      MAX(CASE WHEN pos = 0 THEN word END)   AS word1,
      MAX(CASE WHEN pos = 1 THEN word END)   AS word2
    FROM
    (
      SELECT
        sentence_id,
        word_number - MY_START_NUMBER   AS pos,
        word
      FROM
        sentence_words
    )
      AS offset_sentence_words
    WHERE
      pos IN (0, 1)
    GROUP BY
      sentence_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two tables in my mysql database. Table Name: groups id
I want to grab words from sentences in PHP, for example in the following
Consider the two following programs: program one int main() { printf( hello\n ); }
The following two controls on my page: <asp:LinkButton ID=OpenLB runat=server >Open</asp:LinkButton> <asp:HyperLink ID=OpenHL runat=server>Open</asp:HyperLink>
The following two lines of code load an image from an SVG file and
The following two functions are extremely similar. They read from a [String] n elements,
I have the following two chunks of code, I am not so sure what
Consider the following two EXPLAINs: EXPLAIN SELECT * FROM sales WHERE title != 'The'
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have the following two arrays , i am trying to see whether if

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.