Is there a function in MySQL that will find out the max value in a int column (like in 2, 3, 1, 6, 2, 4 6 is the max)?

    select max(intColumn) from t
    

    Yes, even Mysql has support for that.

      Okay, I am in the middle of programing a message board, but I can't get this to work.
      It is suppost to find out the max number in familyid, and then add one to it, but it always thinks that the number is NULL.
      I have this code

      $query = "SELECT MAX(familyid) from posts";
      	$result = mysql_query($query)	or die("Could not execute query");
      
      $mr = mysql_fetch_array($result);
      $familyid = "$mr[familyid]";
      echo "$familyid";
      $familyid++;
      echo "$familyid";
      GetUserName();
      
      $query = "INSERT INTO posts VALUES
      	('NULL', '0', '$familyid', '$subject', '$post', '$uname',
      	 'NULL', '$forum', 'NULL', 'NULL', '$REMOTE_ADDR', 'RG')";
      
      mysql_query($query)	or die("Could not add post");	
      

      I always get 1 entered for familyid (don't worry about the rest of the columns).

        Use an auto_increment column and dont use select max.

        read it up in the docs.

        You can get the newly inserted value for an auto_increment column by using the function mysql_insert_id()

        If you wish to insert a null into a column the syntax is

        insert into t values(null)

          No, I want to get the max of in there, because all the posts on one topic are going to be the same.

            Write a Reply...