mysql number of rows code example

Example 1: get number of rows in every table mysql

mysql> SELECT table_name, table_rows
   ->FROM INFORMATION_SCHEMA.TABLES
   ->WHERE TABLE_SCHEMA = 'business';

Example 2: mysql num rows

//number of rows retrieved from a query
<?php

$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);

echo "$num_rows Rows\n";

?>

Example 3: row number mysql

SELECT row_number() over ( order by firstName) RowNumberSqeuence,FirstName from rowNumberDemo
 order by FirstName;

Example 4: mysql select count if contains

SELECT sum( case when `tags_Column` CONTAINS 'tag2' then 1 else 0 end ) as tag2,
       sum( case when `tags_Column` CONTAINS 'tag3' then 1 else 0 end ) as tag3,
       .....
       sum( case when `tags_Column` CONTAINS 'tag256' then 1 else 0 end ) as tag256,
       sum( case when `tags_Column` CONTAINS `tag2` OR 
                      `tags_Column` CONTAINS 'tag3`
            then 0 else 1 end ) as doesnt_contains_tags_2_3
FROM `TableContainsTags`

Tags:

Php Example