Getting Employees Having Longest Last Names

image

Need some feedback. I am stuck on what to do. First thing I would think might be to use length

So longest means number of characters so length()?

greatest number of characters also our max() too

Is this homework?

No its one of many review question for future units.

We are doing subqueries right now and are going to use this for later and more complex topics.

Any feedback please:

I am trying to figure it out:

I have error with this right now:

select * from employees
where last_name = (select max(length(last_name)) from employees);

I sure still cannot figure it all out

can anyone support me for some feedback

How will you learn if others help you out? At least please show us something you might have tried?

I did:

select * from employees
where last_name = (select max(length(last_name)) from employees);

I got an error at = for where

does your community answer hw questions btw or just non hw questions

I cant speak for others but personally I try not to answer hw.

  1. You dont learn anything if someone answers it for you
  2. It is not fair to others that cannot find this resources and those that work hard to find the answers themselves

But sometimes I will help someone to guide them to the answer if they have tried hard, have done their due diligencr and they show what they have tried and are really stuck.

What is the error. Since we cant see your computer it is hard to guess and provide you guidance.

hi

hope this helps

create sample data script

drop table if exists #employees
create table #employees ( last_name varchar(20))
insert into #employees select 'Pamela'
insert into #employees select 'SriDevi'
insert into #employees select 'ChungLee'

select 
     top 1  * 
from 
    #employees 
order by 
      len(last_name) desc

image

declare @Longest int

select @Longest = max(len(last_name)) from MyTable
select last_name, [other fields you want to show] from MyTable where len(last_name) = @Longest