0
How can one display an alternative text if there is no record in the database table?
I want to display a placeholder text if there is no data entered in a MySQL database table? I only managed to display when there's something within a table row with the IF, OR , AND and the WHERE conditions. For example: SELECT * FROM table WHERE row id=id number. Now I want something like "Nothing to show" if there is no record at all. Using the above query couldn't display anything since there is no id found in the table.
2 Respostas
+ 1
Hi Chris Lutangu , you can do something like
SELECT
CASE
WHEN Count(rowid) > 0 THEN 'records present'
ELSE 'Nothing to show'
From table WHERE rowid='23';
But, it makes no sense to do this SQL is not a language written to interactively display things, we normally use some backend framework e.g. spring, nodejs, etc. Which talks to the database and can return result according and then a front end written in angular, react or even pure JavaScript which displays this interactively
In short, the function of SQL is to view, add or modify data but it is not used to interactively view it
+ 2
Thanks for the response, I really have been helped.