question

heboy1908 avatar image
heboy1908 asked

projection from a query

i am trying to write a query that would do the following on the *view update_winnerlist which is already GROUPed BY item_index* SELECT email_id (SELECT email_id,min(bid_amount) FROM update_winnerslist AS a1 WHERE a1.item_index = 10 ) i need to perform the above in a single query as i am using it in a trigger to update a table.
sql-server-2005querymysql
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

the update_winnerslist table contains mail_id,item_index,bid_amount attributes.The table is already grouped by item_index values. I am trying to get the email_id for item_index=10 with the lowest bid_amount i.e. the email_id of the person who made the lowest bid on item_index 10.
0 Likes 0 ·

1 Answer

· Write an Answer
Usman Butt avatar image
Usman Butt answered
@heboy1908 I did not understand your requirement properly. But if you want to hit your table only once then the following could be what you want SELECT email FROM ( SELECT email_id, bid_amount, ROW_NUMBER() OVER (ORDER BY bid_amount) ROWNUM FROM update_winnerslist AS a1 WHERE a1.item_index = 10 ) MinBidAmount WHERE [ROWNUM] = 1 Moreover, please keep in mind that there could be ties for the bid amount and if you are doing it in the trigger, you may need to get a random choice or whatever the requirement is. For that the TOP clause may be helpful. PS: RANK() function could be used as well instead of ROW_NUMBER()
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.