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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:57:52+00:00 2026-05-22T11:57:52+00:00

Given the database….. ID Name item_order Manager 1 ted 2 N 2 bob 5

  • 0

Given the database…..

ID     Name     item_order     Manager
1      ted      2                N
2      bob      5                N
3      tony     1                Y
4      fred     3                N
5      william  4                N 
6      george   6                Y
7      cade     8                N
8      matt     7                N

I would like to be able to select managers Id prior to the current non managers name. So for example the result for bob would be tony or 3.

I can figure out how to do this with two requests

SELECT MAX( item_order) AS parent
FROM tablename WHERE item_order < 5 && Manager =  'Y'

The result from that I would make another select by the item_order. Is there a way to do this all in one select?

  • 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-22T11:57:53+00:00Added an answer on May 22, 2026 at 11:57 am
    SELECT * FROM tablename
    WHERE Manager = 'Y'
    AND item_order = (SELECT MAX(item_order) AS parent
                      FROM tablename 
                      WHERE item_order < 5 
                      AND Manager =  'Y') AS t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a model's instance object, how can I get the database table's name? I
Is it possible to get the last created table name in a given database
How would I disable and later enable all indexes in a given schema/database in
Given a database table example: ID Name DateOfBirth Say I wanted to create an
Given a mysql-database with tables as follows: author: +----+----------+ | id | name |
Given a database field named widget_ids, containing data like 67/797/124/ or 45/, where the
I was given a MySQL database file that I need to restore as a
Given a table named person (in a MySQL database/schema), kind of like this one:
For a given form in a database, is there a quick/easy way to find
I was given a task to display when a record in the database was

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.