Skip to main content

SQL Interview Question - 2


Given a table named employees with the following schema:

CREATE TABLE employees (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    department VARCHAR(100),
    salary DECIMAL(10, 2),
    hire_date DATE
);
    

Write a SQL query to find the names of employees who have been with the company for more than 5 years and have a salary greater than $50,000.

 

Sample Data:

INSERT INTO employees (id, name, department, salary, hire_date) VALUES
(1, 'John Doe', 'Engineering', 60000.00, '2016-03-25'),
(2, 'Jane Smith', 'Marketing', 55000.00, '2017-07-10'),
(3, 'Alice Johnson', 'Engineering', 70000.00, '2018-01-15'),
(4, 'Bob Brown', 'Sales', 48000.00, '2019-05-20'),
(5, 'Emily Davis', 'HR', 52000.00, '2015-10-30'); 
 
 

Solution:

SELECT name
FROM employees
WHERE hire_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR) AND salary > 50000; 
 

Explanation:

  • DATE_SUB(CURDATE(), INTERVAL 5 YEAR) calculates the date 5 years ago from the current date.
  • hire_date < DATE_SUB(CURDATE(), INTERVAL 5 YEAR) checks if the employee's hire date is earlier than 5 years ago.
  • salary > 50000 ensures that the employee's salary is greater than $50,000.
  • The SELECT statement retrieves the names of employees who satisfy both conditions.

 

Share your alternate solution in comments.

Comments

Other popular job openings

IDFC FIRST Bank is hiring for an fresher entry level Associate Data Scientist role in India

Some people notified us at 12:30PM on 4th July that the opening is filled and they are not accepting any more applications, please check the other recently posted entry level openings here .    Position: Associate Data Scientist Part of the Data & Analytics function Focused on developing and deploying Generative AI and LLM-based solutions Requires technical expertise in machine learning, NLP, and large-scale data handling Company: IDFC FIRST Bank A new-age Indian bank formed through the merger of IDFC Bank and Capital First Committed to ethical, customer-centric, and tech-driven banking Offers services across retail, MSME, startup, rural, and corporate segments Location: Mumbai, Maharashtra, India Job type: Full-time employment Job mode: Onsite Job requisition id: P-177940 Years of experience: 0 to 2 years Company Description IDFC FIRST Bank was formed after the merger of IDFC Bank and Capital First in 2018 and started full-fledge...

Beco is hiring for a Data Analyst Intern role in India

Position: Data Analytics Intern Company: Beco Location: Mumbai, India Job type: Internship Job mode: Onsite Job requisition id: Not specified Years of experience: 0 years (open to freshers or college students ) Company description : Beco is a sustainability-focused company that develops biodegradable and eco-friendly products Committed to promoting a greener and healthier planet through natural, chemical-free alternatives Emphasizes the use of plastic-free packaging and responsible sourcing of materials Strong focus on community awareness and lifestyle transformation by integrating sustainability in everyday habits Beco envisions an environmentally conscious consumer base and strives to reduce carbon footprint across the value chain Known for integrating eco-conscious values with product innovation and modern-day convenience Active in driving change across households, retail, and e-commerce platforms with transparent and responsible practices ...

Barclays is hiring for an fresher entry level Data Analyst role in India

Position: Data & Analytics Analyst (Data Analyst) Involves hands-on reporting, dashboard creation, and data visualization Focus on analyzing financial data and ensuring regulatory compliance Offers high exposure to data tools and business strategy Company: Barclays Location: Pune, India Job type: Full-time Job mode: Hybrid Job requisition ID: JR-0000058414 Years of experience: 0 to 3 years Company description  Barclays is one of the largest multinational banks headquartered in London The Pune campus is Barclays’ largest location outside of the UK Over 9,000 employees work at this state-of-the-art facility The campus hosts roles across Operations, Technology, and Corporate Functions It is known for a culture of inclusion, innovation, and collaboration The office environment encourages employee well-being and productivity Flexible and hybrid work arrangements are supported Barclays offers a strong learning culture, global exposur...

Fresenius Medical Care is hiring for a fresher entry level Data Analyst role in India

Position: Data Analytics Specialist ( Data Analyst ) Company: Fresenius Medical Care Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: Onsite Job requisition id: R0208600 Years of experience: 0–3 years Company Description Fresenius Medical Care is a globally recognized healthcare company specializing in providing comprehensive services and products to patients with renal diseases. With over 10,000 employees worldwide and decades of experience in dialysis care, the company blends innovation, research, and compassion to offer customized treatment plans. Their offerings include a wide array of medical products and dialysis treatments that are tailored to individual patient needs, covering both in-center and home dialysis options. The company places a strong emphasis on value-based care, aiming to enhance the quality of life for chronically and critically ill patients across the globe. It continuously invests in R&D, operational ...

LSEG is hiring for an fresher entry level Data Scientist role in India

Position: Data Scientist Company: London Stock Exchange Group (LSEG) Location: Bangalore, India (offices at RMZ Infinity and Divyasree Technopolis) Job type: Full-time Job mode: Onsite Job requisition id: R0106477 Years of experience: 0–3 years Company Description: LSEG (London Stock Exchange Group) is a globally recognized leader in financial market infrastructure and data solutions. The company plays a critical role in maintaining global financial stability by offering trusted platforms, infrastructure, and insights that power the financial world. With operations spanning 65 countries and a workforce of over 25,000 professionals, LSEG combines financial expertise with cutting-edge technology to deliver services across capital markets, data analytics, and post-trade solutions. LSEG’s values—Integrity, Partnership, Excellence, and Change—are central to its culture and drive all major decisions and interactions. The company focuses heavily on susta...

Group Bayport is hiring for an fresher entry level Data Analyst role in India

Position: Customer Insights Analyst (Data Analyst) Open for freshers and early-career professionals Focus on Contact Center Customer Quality, VOC programs, and process enhancement Company: Group Bayport A global leader in printing services Operating across multiple brands including BannerBuzz, Covers & All, Vivyx Printing, and more Workforce of over 1450+ employees Known for its entrepreneurial culture, rapid expansion, and employee-driven innovation Location: Gurugram, India Onsite role requiring physical presence in the Gurgaon office Job type: Full-time position Long-term opportunity with potential for internal growth Job mode: Onsite Requires day-to-day collaboration with cross-functional teams Job requisition id: Not specified Years of experience: 0 to 3 years of relevant experience accepted Suitable for freshers with the right skillset and mindset Company description: Group Bayport started as a one-person entrepreneurial star...

AstraZeneca is hiring for an fresher entry level Data Scientist role in India

Position: Data Scientist Entry-level, suitable for candidates with 0 to 3 years of experience Focus on real-world data application, AI models, and ML deployment Opportunity to contribute to healthcare innovation using modern tools Company: AstraZeneca A globally recognized biopharmaceutical company Known for developing and delivering life-changing medicines Active in over 100 countries with a strong presence in India Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: Hybrid (minimum 3 days/week in office) Job requisition id: R-221088 Years of experience: 0 to 3 years Company Description: AstraZeneca is a global leader in the biopharmaceutical space, known for its commitment to advancing science and healthcare. The company focuses on prescription medicines across Oncology, Cardiovascular, Renal, Metabolism, and Respiratory areas. With over 10,000 employees in research and development, AstraZeneca is constantly innovating. ...

eBay is hiring for an fresher entry level Data Analyst role in India

Position: Data Operations Analyst (It is similar to Data Analyst role only) Company: eBay Inc. Location: Bengaluru, India Job type: Full-time Job mode: Onsite Job requisition id: R0068011 Years of experience: 0 to 3 years Company Description eBay is a global ecommerce platform that enables buying and selling in more than 190 markets worldwide. The company has a mission to empower individuals, businesses, and communities through economic opportunity. It was founded in 1995 and has remained committed to shaping the digital commerce space. eBay believes in a culture where authenticity is celebrated and bold ideas are welcomed. The company encourages employees to bring their unique selves to work, contributing to a shared goal of innovation and inclusion. eBay focuses heavily on community-building, aiming to create strong ecosystems for both buyers and sellers. The business operates at an enormous scale, processing millions of transactions daily....

UPS is hiring for a fresher entry level Data Scientist role in India

Position: Title: Data Scientist Skills Required: Python, TensorFlow, SQL, Model Development, ML Lifecycle Department: Enterprise Data Analytics Level: Individual Contributor Company: Name: UPS (United Parcel Service) Industry: Transportation and Logistics Global Presence: Operates in over 200 countries and territories Workforce: Nearly 500,000 employees worldwide Headquarters: Atlanta, Georgia, United States Company Website: ups.com Social Media Presence: Active on Facebook, Instagram, Twitter, YouTube, and TikTok Location: City: Chennai State: Tamil Nadu Country: India Job Type: Employment Type: Permanent Nature of Work: Full-time Domain: Data Science and Machine Learning Job Mode: Mode: On-site  Job Requisition ID: Requisition ID: R25007614 Years of Experience: Experience Required: Not explicitly mentioned, but as per JD looks like an entry level position; 0-3 years Company Description  About UPS: ...

AB InBev is hiring for a fresher entry level Junior Data Scientist role in India

Position: Junior Data Scientist – Predictive Forecasting Company: AB InBev (GCC Services India Pvt. Ltd.) Location: Bengaluru, Karnataka, India Job type: Full-time Job mode: Onsite Job requisition id: 30084171 Years of experience: 0–3 years Company Description (in bullet format) AB InBev is recognized as the world’s largest brewing company. Its vision extends beyond business, striving to bring people together through the culture of beer. The company owns more than 500 beer brands, including globally known names such as Budweiser, Corona, and Stella Artois. AB InBev is committed to sustainable growth that benefits communities, consumers, farmers, and partners alike. Their mission focuses on building a company that will last for a century, investing in both people and local ecosystems. With a long history of uniting cultures over a beer, they continue to evolve in today’s fast-paced, connected world. AB InBev integrates innovation and tradition,...