How to adjust this query?

Asked

Viewed 46 times

0

I need to adjust this query to do the search (like) in another column and another table.

Behold:

$query2 = "select distinct(lances.codigo), datacompra, horacompra, cupom from lances, ".$tabelaCad." where lances.idcliente = ".$tabelaCad.".id and lances.datapgto = '0000-00-00' and lances.horapgto = '00:00:00' and (".$tabelaCad.".nome like '%".$cliente."%' or ".$tabelaCad.".usuario like '%".$cliente."%') group by lances.codigo order by lances.datacompra desc, lances.horacompra desc";

Currently it does the search only on: ".$tabelaCad.".nome e ".$tabelaCad.".usuario.

The variable $tabelaCad is the name of a table called cadastro, and the variable cliente is the one who receives the search POST.

I need her to look in the column too codigo table lances and in a new table called registro in the columns reg1 and reg2.

What would the query look like in this case? I’ve tried several ways and it doesn’t work.

  • If the searches in these other tables have no relation to each other you can use UNION, now if these searches are correlated then you can use JOIN.

  • I couldn’t do it, you can help me with some example?

  • It is difficult to mount select including this table registro If we don’t know what fields she has in common with her select, there’s no way to make a relationship. Could you include in your question the columns of your tables so that we can have an example?

  • In the case of the table registro would need to have a column with the same name as the others? For example the value of reg1 is the same value as lances.codigo...

No answers

Browser other questions tagged

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