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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:34:00+00:00 2026-05-23T19:34:00+00:00

So I am trying to query through a table, call it students if the

  • 0

So I am trying to query through a table, call it students
if the column “status” in Student is ‘active’, then select the “firstName” and “lastName” coloumns from the previous record. Each record has a primary key.
That is, if the “status” column of record is =active, then, i want to select the previos record.
The table is already populated with data like

id  firstname   lastname    status          email
9   Joe         Peters      inactive        fp@gmail.com
10  kim         Rol         active          rt@yh.com
11  Lance       Ree         inactive        lll&hh.com
12  diana       Jones       active          sams@yahoo.com

For this data,the query should return Joe peters and lance ree
How can i do this?
thanks

  • 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-23T19:34:00+00:00Added an answer on May 23, 2026 at 7:34 pm

    If you simply want to select name from the records where the student is active, the query is a simple

    SELECT id, firstname, lastname
    FROM students
    WHERE status = "active"
    

    I assume what you mean by previous row is the row you just determined was an active student. The query will check your table for active students and retrieve their names. Because names are very rarely unique, I included the ID column.
    I also recommend setting the status column to a 0 or 1 integer.

    If you really want to select the previous row, you can use

    SELECT sj.id, sj.firstname, sj.lastname
    FROM students AS s
    LEFT JOIN students AS sj ON (sj.id = s.id - 1)
    WHERE s.status = "active"
    

    The point is in determining the relation between the rows you have and the rows you want to select. In this case, you want to select the row which has the ID 1 less than your current row. Since this constraint is very restrictive, it’s not a good idea to select rows this way. You might want to redesign your database.

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

Sidebar

Related Questions

I'm trying to run a query through the ORM like this: SELECT * from
I'm trying to perform a SQL query through a linked SSAS server. The initial
I'm trying to do a query through NHibernate where the criterion for the result
I am trying to query a table in mysql based on the length of
I have been having trouble searching through a MySQL table, trying to find entries
I'm trying to iterate through some JSON results from the YQL geo.places table using
I'm trying to take an ADO Recordset and then loop through it to parse
I'm trying to do a query through NHibernate where the criterion for the result
I'm trying to query 2 tables to generate records for a third table which
I am trying to insert data in table in mysql database through php code

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.