Friday, October 10, 2014

MySql query to select count of only max value from table in PHP

CREATE TABLE tableName  // Give any name as u like
(
     id int auto_increment primary key,
     party varchar(20),
     constituency varchar(30),
     votes int(11)
);

Then insert some details.
I inserted these details :)

INSERT INTO tableName
          (party, constituency,votes)
VALUES
          ('BJP', 'Surat',1200),
          ('Congress', 'Surat',1100),
          ('BJP', 'Baroda',800),
          ('Congress', 'Baroda',900);

Query :)

mysql_query("select max(votes) from tableName group by constituency");

Output :)


No comments:

Post a Comment