Concatenation OR, AND, ORDER BY and RAND() do not work

Asked

Viewed 40 times

0

I’m with the following SQL:

SELECT id,titulo,slug,endereco
FROM empresas
WHERE
(categoria = ".$_GET['id']." OR categoria_2 = ".$_GET['id']."  OR categoria_3 = ".$_GET['id'].") AND (status = '1') ORDER BY chave DESC, RAND()

But he doesn’t order through the key field and neither does Rand()

I try to manipulate the "parentheses" there the status = '1' crashing.

How do I make that line work the structure OR, AND, ORDER BY and RAND() ?

  • 1

    Give an example of the data you have in the table and the result you want to get

  • 1

    Some databases and some situations require the "order" cmpo to be in "select", if "key" is unique the order by Rand() would not make sense

  • @Motta My database is MYSQL

No answers

Browser other questions tagged

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