query problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

query problem

Post by itsmani1 »

I am having a problem with query, I want to select max bid price, primary key, and FK_PRODUCT_ID against a user id. but i want to select row if and only if the user put max bid in other words i want to select max bid, product id, pkid against a user id if and only if he/she has given max bid on that product.

Here is db structure:

Code: Select all

CREATE TABLE `bids` (
  `PK_ID` int(11) NOT NULL auto_increment,
  `FK_USER_ID` int(11) default NULL,
  `FK_PRODUCT_ID` int(11) default NULL,
  `bid_price` float(11,0) default NULL,
  `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`PK_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: query problem

Post by califdon »

itsmani1 wrote:I am having a problem with query, I want to select max bid price, primary key, and FK_PRODUCT_ID against a user id. but i want to select row if and only if the user put max bid in other words i want to select max bid, product id, pkid against a user id if and only if he/she has given max bid on that product.
How about:

Code: Select all

SELECT * FROM bids ORDER BY bid_price DESC LIMIT 1
Post Reply