Does not return the amount of records from the Postgresql database

Asked

Viewed 127 times

1

I would like to know the amount of records in my database, but does not return the amount.

Look at the records in my database

inserir a descrição da imagem aqui

SQL command

Select count(*) as contaRegistros from tb_produtos where prod_nome like '%"+  +"%';

Upshot

inserir a descrição da imagem aqui

  • Your Where is half wrong, what your intention with it?

  • I want to search the quantity according to the name , in case the result of this select I put was to return all records since the search field is empty

1 answer

1


Just do it this way:

Select count(*) as contaRegistros from tb_produtos;

It’s not working because of your Where:

where prod_nome like '%"+  +"%';

You must have copied it from some chunk of code wrong.

If you need to research some value, do it this way, let’s assume that the searched value is 'test':

Select count(*) as contaRegistros from tb_produtos where prod_nome like '%teste%';
  • but then Wictor and if in the future I want to search the quantity according to the name , in case the result of this select I put was to return all records since the search field is empty

  • There you have to put so Where prod_name like '%%'; there it will fetch everything and if you are going to do some research prod_name like '%value%'; of course it will depend on the language you are using, if you are using only in the direct flock this way will work.

  • I put the command you said but did not return all records Select Count(*) as contaRegistros from tb_products Where prod_name like '%" "%';

  • you have to do without the "": Select Count(*) counts from tb_products Where prod_name like '%%';

  • If you put the "" it will research values that have "".

  • and if I wanted to put this command in java for example how it would be ?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.