I need to do a search that specifies in witch line of the search that the information was found. For example:

select * from table where height=100;

this code returns 50 lines, but i want, for example, in that search, the person 'Matheus' was in the 28th line of the search above

Recommended Answers

All 3 Replies

Member Avatar for diafol

If you want specific data...

select * from table where height=100 LIMIT 27,1;

Will give you just the 28th record for a record with height set to 100.

usually,m you wouldn't know which limit offset to use, so you could do this...

select * from table where height=100 AND firstname='Matheus' LIMIT 1;

That would give you the first hit for a record having height set to 100 AND a firstname of 'Matheus'. If you have multiple recults and want the last one only...

select * from table where height=100 AND firstname='Matheus' ORDER BY id DESC LIMIT 1;

Assuming that you have a PK autoinc field called 'id'

But I dont know that Matheus is the 28th name of the select statement, but I want to know. For example:

the following table 'persons':

name height
Jean 100
Matheus 98
Joseph 99
Mary 95

and the select:

select * from persons where ?????????;

and returns:

Matheus was in the 2nd line

SELECT @line := @line + 1 AS line, persons.*
FROM persons, (SELECT @line := 0) temp
commented: nice one! +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.