I
I
iOS Dav2016-08-09 22:07:31
SQL
iOS Dav, 2016-08-09 22:07:31

How to stop count (sql query) after it finds 1 record?

SELECT COUNT(id) as c FROM users where login="bek" limit 1 - tried but still finds 27 (27 records in the table).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2016-08-09
@melkij

Do you need to know if there is such a record? What for then count?
The string returned - it means there is. Returned 0 lines - so no.
You can always return one row:

SELECT EXISTS(SELECT 1 FROM users where login="bek" limit 1)

A
Alexey, 2016-08-09
@k1lex

Why do you need to choose the quantity if you already choose only 1 ???
Choose 1 ID, and then according to the situation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question