Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL get all results but first [duplicate]

Tags:

mysql

Possible Duplicate:
Mysql Offset Infinite rows

I am trying to get all results for a query BUT NOT the first one, I have the following but its giving me an error, please help; thanks.

SELECT DISTINCT `memberID` FROM `discusComments` 
WHERE `topicID` = 4 ORDER BY `id` DESC OFFSET 1
like image 495
Jake Avatar asked Aug 17 '11 19:08

Jake


People also ask

How do I find duplicate values in MySQL?

Find duplicate values in one column First, use the GROUP BY clause to group all rows by the target column, which is the column that you want to check duplicate. Then, use the COUNT() function in the HAVING clause to check if any group have more than 1 element. These groups are duplicate.

How do I remove duplicate results in MySQL?

Eliminating Duplicates from a Query Resultmysql> SELECT DISTINCT last_name, first_name -> FROM person_tbl -> ORDER BY last_name; An alternative to the DISTINCT command is to add a GROUP BY clause that names the columns you are selecting.

How do I find duplicate records in SQL Server without GROUP BY?

The query uses window version of COUNT aggregate function: the function is applied over Col1 partitions. The outer query filters out records which have a Col1 value that appears only once. Show activity on this post.


2 Answers

SELECT DISTINCT `memberID` 
FROM `discusComments` 
WHERE `topicID` = 4 
ORDER BY `id` 
DESC limit 1,x

where x is a number enough great to contain all your records.

or use, instead of x, 18446744073709551615, that is maximum value of bigint unsigned.

like image 116
Nicola Cossu Avatar answered Sep 28 '22 18:09

Nicola Cossu


Ignore the first row when you receive the results in your application. It is much neater than using an ugly query like:

SELECT * FROM my_table LIMIT 1, 18446744073709551615

Getting one extra row will not really hurt your performance.

like image 29
nobody Avatar answered Sep 28 '22 18:09

nobody