In the SQL query, only the first 10 linesWhen processing large datasets, display all results may not be necessary or ideal. Limit the number of results displayed usually helps optimize performance and improve readability. This can be achieved through a simple and effective technology, which is called line restrictions.
In SQL Server, the line restrictions are executed using the "TOP" clause. By specifying a number (for example, 10) at the beginning of the inquiry, you can indicate that the database only retrieves the number of the number.
For example, to modify the query provided to display only the first 10 results:
In MySQL, the restrictions are implemented using "Limit" clauses. You do not need to use "TOP", but attach "Limit" to the end of the number of rows (eg, 10) to the end of the query.
<code class="language-sql">SELECT TOP 10 a.names, COUNT(b.post_title) AS num FROM wp_celebnames a JOIN wp_posts b ON INSTR(b.post_title, a.names) > 0 WHERE b.post_date > DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY a.names ORDER BY num DESC</code>Copy after loginFor MySQL, the query after modification is shown below:
The above is the detailed content of How to Select Only the First 10 Rows in SQL Queries (MySQL and SQL Server)?. For more information, please follow other related articles on the PHP Chinese website!