简体   繁体   中英

Return only one tuple of SQL query result

I want to do a query like

select * from chr2;

but only have MySQL return the first tuple (or an arbitrary) tuple instead of all of them.

How do I do it?

Use the LIMIT clause:

SELECT * FROM chr2 LIMIT 1;

If you want an arbitrary row returned, you have to sort your rows by an random col like this ( MySQL docu ):

SELECT * FROM chr2 
ORDER BY RAND()
LIMIT 1;

On large tables, however, you might run into performance problems with this, as there a random value has to be created for each row and the table has to be sorted according to this column.

尝试这个 ::

select * from chr2 limit 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM