0

i am writing a query like below to retrieve a specific value from the table based the certain value.

select name from XXX where number="2033"

this query will search in whole table. Now i want this query should only check from 4th row to last row and return me the result . that means even if the value is present in 2nd row also it should return me null value or blank value

sss
  • 21
  • 3

2 Answers2

1

I think this will do the trick.

select
    name
from (
    select
       *,
       @rowno := @rowno + 1 rowno
    from XXXX
    cross join (select @rowno := 0)
    order by some_col) t
where rowno >= 4
and number = '2033'

Or without subquery:

select
   name,
   @rowno := @rowno + 1 rowno
from XXXX
cross join (select @rowno := 0)
where number = '2033'
order by some_col
having rowno >= 4
Blank
  • 12,308
  • 1
  • 14
  • 32
-1

you can write the query as below :

select 'name' from XXX where number= "2033" order by id desc limit 0,4;
Anandhu Nadesh
  • 672
  • 2
  • 11
  • 20
Rajv
  • 1