Skip to main content

Posts

To fetch highest row in table

SELECT * FROM `bids` as b where amount = (select max( amount) from bids where userid = b.userid) and timestamp = (select max( timestamp) from bids where userid = b.userid) group by userid For examples id userid timestamp amount 1 101     1122334  223 2 102     1222334  323 3 101     1322334  523 4 102     1522334  723 5 101     1622334  283 6 102     1722334  293 7 102     1822334  233 8 102     2222334  203 id userid timestamp amount 1 101      1622334 283 2 102      2222334 203

Mysql: Multiple loop cursor in procedure

DELIMITER $$ DROP PROCEDURE IF EXISTS `updatequestion` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `updatequestion`()  BLOCK1: begin      declare v_col1 int;      declare no_more_rows1 boolean default FALSE;      declare cursor1 cursor for          select col1          from   MyTable;      declare continue handler for not found          set no_more_rows1 := TRUE;      open cursor1;      LOOP1: loop          fetch cursor1          into  v_col1;          if no_more_rows1 then              close cursor1;         ...

Mysql Procedure syntax

DROP PROCEDURE `dg`// CREATE DEFINER=`root`@`localhost` PROCEDURE `dg`(g int(32)) begin declare p_a int(25); declare no_more_rows boolean default FALSE; declare cursor1 cursor for select id from chk; declare continue handler for not found set no_more_rows := TRUE; open cursor1; Loop1 : loop fetch cursor1 into p_a; if no_more_rows then close cursor1; leave Loop1; end if; select p_a; end loop Loop1; end

Mysql : Rollup command ..last row of the result will show the total of sum and count function

Rollup command ..last row of the result will show the total of sum and count function SELECT month,sum(star),sum(rating),count(*) FROM `rolluptest` group by month with rollup +-------+-----------+-------------+----------+ | month | sum(star) | sum(rating) | count(*) | +-------+-----------+-------------+----------+ | Feb   |        19 |           4 |        3 | | Jan   |         9 |           4 |        2 | | Mar   |         1 |           3 |        1 | | NULL  |        29 |          11 |        6 | +-------+-----------+-------------+----------+

Joomla : Add joomla modules in our Custom Component

function display()  {   global $mainframe;   $model =& $this->getModel("vadmin");   $a = new CTemplate();   $a->setfile("home");     $article->text = $a->fetch();   $params =& $mainframe->getParams();   $dispatcher =& JDispatcher::getInstance();   JPluginHelper::importPlugin('content');   $results = $dispatcher->trigger('onPrepareContent', array (& $article, & $params));   echo $article->text ;     }