Get highest or second highest or lowest values from table – MYSQL

Hi Guys,
Today I share some useful topic related to MYSQL. The MYSQL is very helpful in our project or queries for different functionality.
The MYSQL is most popular Open source management system.

Suppose that, you are given the following simple database table called EmployeeDetails table that has two field like EmployeeID and Salary. We can fetch the data from database and also fetch content from database table based on condition.

It is easy to select the highest or lowest record in the database table with the MAX or MIN function.

Fetch Full data from database table as EmployeeDetails:

select * from EmployeeDetails;

EmployeeID Salary
1 4000
2 8000
3 8500
4 14000

Get the highest salary from the table EmployeeDetails:

Select MAX(Salary) from EmployeeDetails;

Running the SQL above would return us 14000, which is of course the highest salary in the EmployeeDetails table.

Get the second highest salary from the table EmployeeDetails

SELECT MAX(Salary) FROM EmployeeDetails WHERE Salary NOT IN (SELECT MAX(Salary) FROM EmployeeDetails);

Running the SQL above would return us 8500, which is of course the 2nd highest salary in the EmployeeDetails table.
Code Explanation:The SQL above, first find the highest salary values from the EmployeeDetails table using “Select MAX(Ssalary) from EmployeeDetails”. Then, adding the “WHERE Salary NOT IN” in front basically creates a new set of Salary values that does not include the highest Salary value. For instance, if the highest Salary in the EmployeeDetails table is 14000 then that value will be excluded from the results using the “NOT IN” operator, and all values except for 14000 will be retained in the results.

Here is another SQL query to find second highest salary using subquery and < operator instead of IN clause:

SELECT max(salary) FROM EmployeeDetails WHERE salary < (SELECT max(salary) FROM EmployeeDetails);

Running the SQL above would return us 8500, which is of course the 2nd highest salary in the EmployeeDetails table.

Get the lowest salary from the table EmployeeDetails:

Select MIN(Salary) from EmployeeDetails;

Running the SQL above would return us 4000, which is of course the 2nd highest salary in the EmployeeDetails table.

One thought on “Get highest or second highest or lowest values from table – MYSQL

  1. female cutting Cycle Steroids

    As a specialist in inflammatory bowel illnesses, Waljee prescribes steroids usually to
    patients looking for aid from chronic digestive
    tract points. The medicine that thickened Heather’s vocal cords,
    giving her not only a manly voice but in addition impressive
    muscle tissue and a chiseled jaw, are technically generally
    known as AAS, for anabolic-androgenic steroids.

    They’re all chemical derivatives of testosterone, which explains the anabolic (muscle-building) features in addition to the androgenic (masculinizing)
    bugs.
    A barrier to this is that the framework to talk about mens’ and boys’ physique
    issues doesn’t exist. There’s an absence of attention to
    problems like body dysmorphia and eating problems in males and boys.

    Coupled with the dearth of transparency around steroids and other PEDs, it raises the question of what
    we all think the male body is meant to look like. His youthful sufferers usually search
    for celebrities’ exercise routines in the hope they’ll copy them.
    The exhausting part, Olivardia said, is making it clear to boys that it’s unrealistic to attain these kinds of our bodies with out the chefs, trainers, cash, and sometimes substances that these
    actors have access to. Body dysmorphia is a dialogue we’ve been having culturally for many years, but mostly
    as it concerns ladies and ladies. Standards of beauty for the female cutting Cycle Steroids body have
    long been exacting and unrealistic.
    Thus, overly dramatic trenbolone earlier than and after photos are unusual,
    as most of a steroid user’s results occur within the first
    few cycles, usually on testosterone or milder compounds corresponding to Anavar.
    This is due to Winstrol being a toxic steroid and
    thus not appropriate for beginners. Nevertheless, if novices are adamant about taking Winstrol, a cycle of 8–10 mg/day for 6
    weeks notably reduces side effects in our sufferers.
    The effects of the steroid period prolonged past particular person gamers and reached the very core of the game.

    Baseball’s record books had been tainted, and the notion of the sport eternally modified.

    The period of steroids left an indelible mark on baseball, forcing us to question the achievements of gamers and the overall integrity of the game.
    It serves as a reminder that the pursuit of greatness should at all times be rooted in fair play and respect for the principles.

    Adolescents and younger adults should be taught concerning the risks of taking anabolic steroids beginning in middle college.
    Additionally, applications that train different, healthy ways to
    extend muscle dimension and enhance efficiency could also be helpful.
    Such applications emphasize good vitamin and weight coaching methods.

    Anadrol and Winstrol are probably the most potent anabolic
    (muscle-building) compounds for women, as mentioned on this article.
    Different anabolic steroids may also trigger exceptional ranges of muscle hypertrophy, similar to trenbolone or testosterone; however,
    they do not seem to be suitable for girls seeking to preserve their womanhood.

    The course of by which Deca-Max works is that it promotes protein synthesis and nitrogenretention, which aids in increasing muscle
    mass and, due to this fact, power. This also aids inthe
    health of the joints and, therefore, is better throughout intense exercises.

    D-Bal works via the elevation of nitrogen within the muscle tissue, starting the process ofProtein Synthesis,
    which aids in increasing muscle mass and strength.
    The biological function of anabolic (tissue building) steroids like Dianabol is to stimulate
    protein synthesis – that is, to heal muscle tissue extra shortly and successfully.
    New muscle is gained by tearing the long, tube-like fibres that run the length of our muscle; protein molecules attach to
    the broken chains, creating new muscle. Whereas on steroids, your muscle fibres turn into
    grasping, seeking out each stray protein molecule.

    However it does give them extra vitality for their exercises and faster restoration. That,
    combined with a better mood and a higher intercourse drive,
    are all his clients need or feel they want from the medication. While their health dangers differ by
    the type and quantity taken, they are often dangerous and
    trigger unwanted effects at any dose. Corticosteroids
    are one other sort of steroid naturally produced in your body to assist regulate inflammatory immune processes.

    A/A ratio, anabolic–androgenic ratio; IM, intramuscular injection; PO, oral.
    The emergency and referral assets listed above can be found to people
    located in the United States and usually are not operated by the National Institute on Drug Abuse (NIDA).

    NIDA is a biomedical analysis group and does not present customized medical recommendation, therapy,
    counseling, or authorized session. Information supplied
    by NIDA just isn’t an alternative alternative to professional
    medical care or legal consultation.
    You should contact your advice line urgently when you assume you
    could have an infection. You may get some of them, however it is
    extremely unlikely that you’ll have all of them.
    He was honest in regards to the unwanted effects
    — although claimed he largely didn’t experience
    them, and knew tips on how to deal with them with he did.

Leave a Reply

Your email address will not be published.