Is it possible to use IF within the FROM in MySql?

-1

Could it be IF within FROM ? I searched but could not find anything about it.

Here is an example of what I want to do:

SELECT usuario.* FROM (
  SELECT
  IF( 
    (SELECT COUNT(*) FROM pessoa) > 0, 
    SELECT  FROM pessoa,
    SELECT * FROM clliente, 
  ) AS usuario
)

NOTE: Since the bank architecture was developed the worst way, I'm having to do some crazy SQL.

    
asked by anonymous 24.05.2016 / 22:13

2 answers

1

One solution might be to create a view

create or replace view v_pessoa_cliente
as
select cpf , nome from pessoa
union
select cpf,nome from cliente

In the application do

select *
from v_pessoa_cliente
where nome = 'Daniel Dutra'
    
24.05.2016 / 23:01
0

Simplifying this way would not solve your case?

SELECT IF(COUNT(p.*) > 0, p.*, c.*) as usuarios_maior_volume
FROM pessoas p, clientes c;

And to get global:

SELECT * FROM pessoas, clientes;

And to bring it all:

SELECT * FROM pessoas
union all
SELECT * FROM clientes;
    
24.05.2016 / 23:15