sarmenhbb
sarmenhbb

Reputation:

what is this sql statement doing? (mysql)

SET @row := 0;
SELECT * FROM (
SELECT @row := @row+1 AS rank, account_id, keyword, bid_amount ,timestamp
FROM bids WHERE keyword='programmers'
ORDER BY bid_amount DESC, timestamp ASC
) AS derived_table; 

i saw this somewhere and i was wondering what the set does along with the @ sign and the :=

thanks

Upvotes: 2

Views: 93

Answers (1)

Eric
Eric

Reputation: 95133

It's creating a row number column.

@row is an integer variable. := sets the variable for each row, taking the previous row's value of @row. So, you get a nicely incrementing column which tells you what number row you're on.

Upvotes: 6

Related Questions