Welcome Guest, Not a member yet? Register   Sign In
mysql help
#1

[eluser]quasiperfect[/eluser]
how can i add from mysql a incrementing value to each row i get from a query ?
i'm not talking about auto incrementing a existing value.

example :
Quote:select round((sum(votes.vote) / count(votes.id)),2) AS vote, count(votes.id) AS nrvotes, ("value"+1) as position FROM votes, users WHERE users.id = votes.person order by vote,nrvotes,position desc

where "value" is not in any of the 2 tables is just the place in the results

this is just a example my query is much more complex

i want to add a value starting from 1 an incrementing it for each row.
i need to do this from inside the query not from php
#2

[eluser]xzela[/eluser]
Hi,
What are the benefits of performing this action within SQL?
To solve this problem you can try a subquery. It may or may not work:
Code:
SELECT
  (SELECT COUNT(*) FROM table WHERE something = something_else) + 1 AS position
FROM
  another_table
WHERE
  column = something




Theme © iAndrew 2016 - Forum software by © MyBB