0

I have this mysql code witch is working very well

SELECT uid , MAX(value) AS bidvalue FROM auction 
WHERE pid = '$pid' and max_bid=0 
GROUP BY uid 
ORDER BY bidvalue DESC 
LIMIT 1

How can I join this selection with users table ON users.id=auction.uid?

Thank you

bmargulies
  • 97,814
  • 39
  • 186
  • 310
Coscho
  • 89
  • 1
  • 1
  • 9

2 Answers2

1

I don't see any magic here:

SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction 
INNER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0 
GROUP BY uid 
ORDER BY bidvalue DESC 
LIMIT 1
Olivier Coilland
  • 3,088
  • 16
  • 20
1

You may use join for that your query might look like

SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction 
INNER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0 
GROUP BY uid 
ORDER BY bidvalue DESC 
LIMIT 1

or

SELECT uid, users.name, MAX(value) AS bidvalue
FROM auction 
OUTER JOIN users ON users.id = auction.uid
WHERE pid = '$pid' and max_bid=0 
GROUP BY uid 
ORDER BY bidvalue DESC 
LIMIT 1

with the joins details as per your need

Community
  • 1
  • 1
NoNaMe
  • 6,020
  • 30
  • 82
  • 110