0

I need the check the table is empty or not employee table contains columns are id name

id  name
1   john 
2   hunter
3   smith
4   will

2 Answers 2

2

If your table can contain a lot of rows, you can win some time with

SELECT count(*) FROM (select 0 from employee limit 1);
2
  • it's your query very nice but the optimized query is (select 1 from employee limit 1;) , is that efficient and simple query
    – somesh C K
    Commented Nov 29, 2018 at 10:18
  • Yes, but handling the result is more complex. Commented Nov 29, 2018 at 10:39
0

A table is empty if select count(*) from employee returns 0.

1
  • it takes to much time and in worst case it have ten thousand rows it count all the rows, so it take too much amount of time
    – somesh C K
    Commented Nov 29, 2018 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.