Query DB and show all results except first

3

I have the tbl_galeria table, what happens is that I want to make a query, but the query can not show the first result. That is, the query will return all values except the one with the smaller id.

$query = mysql_query("SELECT * FROM tbl_galeira ORDER BY id ASC");
    
asked by anonymous 02.07.2014 / 15:23

4 answers

5

You can do with MIN of MySQL:

$query = mysql_query("SELECT * FROM tbl_galeira WHERE id > (SELECT MIN(id) FROM tbl_galeira) ORDER BY id ASC");
    
02.07.2014 / 15:29
4

Simple and straightforward solution without subquery:

$query = mysql_query( 'SELECT * FROM tbl_galeira ORDER BY id LIMIT 1,999999999' ).

Just the second parameter of LIMIT is absurdly larger than what your application wants to store. Remember that 0 is the first record, so we used 1 to pick up from the second on.

It may seem strange to syntax, but it is more effective than engine comparing IDs line by line (and more readable).

    
02.07.2014 / 20:07
2

You can do a subquery:

SELECT * 
FROM tbl_galeira, 
    (SELECT id as fId FROM tbl_galeira ORDER BY id ASC limit 1) f 
WHERE id > f.fId
    
02.07.2014 / 15:30
0

It's interesting to know how many records you want to return. Let's say it's 10, you would do the following:

$query = mysql_query("SELECT * FROM tbl_galeira ORDER BY id ASC LIMIT 10, 1");
    
02.07.2014 / 19:40