MySQL Query bulmaca

3 Cevap php

I have a table with two fields (id and word). Can anyone enlighten me as to why:

$query0 = "SELECT * FROM words WHERE id IN ($treated_words) ";

geçerli bir sorgu olduğunu. Ancak:

$query0 = "SELECT * FROM words ORDER BY id ASC WHERE id IN ($treated_words) ";

değildir. Çok teşekkürler

3 Cevap

Bir SQL sorgusu konularda elemanların al. ORDER BY fıkra WHERE fıkra sonra görünmesi gerekir.

Sözdizimi kuralları için MySQL dokümanlar bak. Sen gibi bir şey görürsünüz

SELECT [ DISTINCT | ALL ]
  column_expression1, column_expression2, ....
  [ FROM from_clause ]
  [ WHERE where_expression ]
  [ GROUP BY expression1, expression2, .... ]
  [ HAVING having_expression ]
  [ ORDER BY order_column_expr1, order_column_expr2, .... ]

WHERE id IN ($treated_words) parçası sonra ORDER BY id ASC taşımak deneyin.

Nerede deyimi önce order_by olamaz.

MySQL works this way. it selects everything or certain fields from table, applies to filter (where) and than orders by id. so that is why you can't order selected data and then apply filters to it.