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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:50:44+00:00 2026-05-16T08:50:44+00:00

so lets say i have a table called data data id | date |

  • 0

so lets say i have a table called data

data

id | date      | name
---------------------    
1  | 19/8/2010 | John    
2  | 19/8/2010 | Mary    
3  | 20/8/2010 | Peter    
4  | 20/8/2010 | Bert     
5  | 20/8/2010 | Ernie 

if i do a select statement like this

SELECT * FROM data where date = '20/8/2010';

is it possible to edit this select statement to take the row before it as well. in this case it returns me row number 3 – 5. but is is possible to edit the sqlstatement in any way to select row 2 as well?

  • 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-16T08:50:45+00:00Added an answer on May 16, 2026 at 8:50 am

    Adapting @SteveCav’s solution to UNION with the original query:

    SELECT d.* 
    FROM   data d
    JOIN   (
              SELECT MIN(id) lowest_id
              FROM   data 
              WHERE  date = '20/8/2010'
           ) dt ON (dt.lowest_id - 1 = d.id)
    UNION
    SELECT * 
    FROM   data 
    WHERE  date = '20/8/2010';
    

    Test case (tested in sqlite 3):

    CREATE TABLE data (id int, date date, name varchar(10));
    
    INSERT INTO data VALUES (1, '19/8/2010', 'John');
    INSERT INTO data VALUES (2, '19/8/2010', 'Mary');
    INSERT INTO data VALUES (3, '20/8/2010', 'Peter');
    INSERT INTO data VALUES (4, '20/8/2010', 'Bert');
    INSERT INTO data VALUES (5, '20/8/2010', 'Ernie');
    

    Result:

    id          date        name      
    ----------  ----------  ----------
    2           19/8/2010   Mary      
    3           20/8/2010   Peter     
    4           20/8/2010   Bert      
    5           20/8/2010   Ernie 
    

    This is assuming that by “the row before”, you intend the row with the previous id value.

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

Sidebar

Related Questions

I have the following mysql table called test. lets say it has the data
Lets say I have one table called REVIEWS This table has Reviews that customers
Lets say I have a table in MySQL called articles, that has a column
Lets say I have a database table called Scrape possibly setup like: UserID (int)
Let's say I have a table called Person with the columns: id, name, parent_id
lets say I have a table called table1 and it's corresponding columns are col1,
Lets say i have table called Orders id qty1 qty2 qty3 ----------------------------------- 1 1
Lets say I have a table called orders, where each row stores an id,
i have 2 tables 1st table called services has id_service, name, date. description 2nd
Let's say I have a table called messages with the columns: id | from_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.