SQL Interview Question: Find the Last Record in a Table (SOLVED!)

preview_player
Показать описание
Ace your SQL interview with this simple query!
In this video, I will teach you the most efficient way to write a SQL query to find the last record of a table. This is a common interview question, so knowing the answer will give you a leg up on the competition.
In addition to the video tutorial, I will also provide you with some tips for answering SQL interview questions effectively. So if you're preparing for a SQL interview, be sure to watch this video!

-------------------------------------------------------------------------
►►►Social Media – Where I sort of Live
-------------------------------------------------------------------------
►►►Books I refer to
-------------------------------------------------------------------------
►►►Camera Gears
► Video Gears That We Use For Creating Our YouTube Video

► Work From Home Essential Tech That We Use Daily

AFFILIATE DISCLOSURE:
#RebellionRider
Рекомендации по теме
Комментарии
Автор

What is the last record of the table is not having the highest employee id number?
Or what if there is no employee id?
At that time you need to make a row number and then you can do the orderby desc to find the last or the bottom most entry.

sidmoitra
Автор

We can use arbitrary rownum keyword by which we’ll be able to have rownumbers and then we can sort sort it on the basis of rownum

AmanSharma-roze
Автор

Order by clause may leads to performance impact if the table size is big

arjunm
Автор

Bro if there is emp_id column not present then how

prafulyelekar
Автор

This only works if primary id is incremented order.

sujanbhattarai
Автор

Do they hard sql question for fresher role for data analyst role or something like this in the video?

AbhishekSharma-vmtr
Автор

What if you simply did a select top 1 and order by 1 desc?

sheldonbanks
Автор

bro last query is wrong. what if your last record is not highest according to your key

ankitsisodiya
Автор

Instead of emp column
Its better to use pseudo columns, if you use oracle. .. Like below two ways

Way1:
With cte as(
Select .*from HR. employees
Order by rowid desc
)
Select * from cte
Where Rownum=1

Way2
Select * from(
Select *from HR. Employees
Order by rowid desc
)
Where rownum =1
Nice question!!

Tech.S
Автор

Select * from (Select rownum r, empno from employee)where r=(select count(*) from employee) is this correct?

hopess-nmij
Автор

This question is too ambigious. What if we want the last record according to first name or x column and NOT emp id

thekristianbuddyshow
Автор

Bruh. This is too ez..this only works if the empid is ordered properly..what if in your dataset the rows are jumbled and you want to retrieve the last record..
They ask such cross questions in interview

guiltycrown
Автор

last record is ambiguous...last record changes with what you sort on... stupid question

nid