<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>MySQL Forums - MySQL Query Analyzer</title>
        <description>Forum for MySQL Query Analyzer</description>
        <link>http://forums.mysql.com/list.php?166</link>
        <lastBuildDate>Wed, 19 Jun 2013 14:01:01 +0000</lastBuildDate>
        <generator>Phorum 5.2.19</generator>
        <item>
            <guid>http://forums.mysql.com/read.php?166,588402,588402#msg-588402</guid>
            <title>SELECT ... SELECT IN MYSQL (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,588402,588402#msg-588402</link>
            <description><![CDATA[ I am trying to write a query for mysql (Search Module) where I am facing difficulties because of the select operation to be carried out inside same table.<br />
<br />
My Query:<br />
<br />
(SELECT * FROM user WHERE `user_name` like '%TOM%' OR `user_name` like '%AN%' <br />
and `login_datetime` BETWEEN '2013-01-01 00:00:00' and '2013-02-31 23:59:59')<br />
    OR<br />
(SELECT * FROM user WHERE `user_name` like '%PHP%' OR `user_name` like '%BA%' <br />
and `login_datetime` BETWEEN '2013-02-01 00:00:00' and '2013-03-31 23:59:59')<br />
    AND<br />
(SELECT * FROM user WHERE `user_name` like '%SUN%' OR `user_name` like '%MOON%' <br />
and `login_datetime` BETWEEN '2013-03-01 00:00:00' and '2013-04-31 23:59:59') <br />
    NAND<br />
(SELECT * FROM user WHERE `user_name` like '%RAJ%' OR `user_name` like '%MUTH%' <br />
and `login_datetime` BETWEEN '2013-04-01 00:00:00' and '2013-06-31 23:59:59') <br />
    NOR<br />
 (SELECT * FROM user WHERE `user_name` like '%BAG%' OR `user_name` like '%LAP%'<br />
 and `login_datetime` BETWEEN '2013-05-01 00:00:00' and '2013-07-31 23:59:59')<br />
The above mentioned query is my scenario.. Where this cannot be changed, I am trying to write a Query for this.<br />
<br />
Note:<br />
The above query execute in a single table.<br />
OR, NAND, NOR, AND operation can be inter-changed with according to the situation.<br />
It depends with the user, how he needs to search.<br />
I tried many ways to achieve the logic but I am facing issues in all phases.]]></description>
            <dc:creator>Aravind Kumar</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 11 Jun 2013 13:48:16 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,586296,586296#msg-586296</guid>
            <title>Query running very slowww.. (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,586296,586296#msg-586296</link>
            <description><![CDATA[ Hi all I am stucked up in a perfomance issue,<br />
<br />
I have this query I need to run on the server,<br />
<br />
SELECT COUNT(1) AS removedItems, c.identity AS userId, c.email_address, DATE_FORMAT(sc.stateTs, '%m/%d/%Y') AS completedDate <br />
FROM changeList.ContactStatusChange sc JOIN jobCntrl.Job j ON sc.job_guid = j.job_guid LEFT JOIN webAcctTrans.client c ON j.authorClient_id = c.identity <br />
WHERE sc.changeStateType = 5 AND sc.createTs &gt; '2013-04-01 00:00:00' AND sc.createTs &lt; '2013-04-30 23:59:59' <br />
GROUP BY userId ORDER BY c.email_address asc;<br />
<br />
<br />
 show index from changeList.ContactStatusChange;<br />
+---------------------+------------+-----------------------------------------+--------------+--------------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| Table               | Non_unique | Key_name                                | Seq_in_index | Column_name              | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br />
+---------------------+------------+-----------------------------------------+--------------+--------------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| ContactStatusChange |          0 | PRIMARY                                 |            1 | contactValidityChange_id | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          0 | uk_job__personstaging_id                |            1 | personStaging_id         | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          0 | uk_job__personstaging_id                |            2 | job_guid                 | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          0 | origin_identity                         |            1 | contactValidityChange_id | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          1 | personstaging_identity__changeDate      |            1 | personStaging_id         | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          1 | personstaging_identity__changeDate      |            2 | createTs                 | A         |   125530870 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          1 | changeDate                              |            1 | createTs                 | A         |      224563 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          1 | fk_personstagingAccuracyChange_Job1     |            1 | job_guid                 | A         |          18 |     NULL | NULL   |      | BTREE      |         |               |<br />
| ContactStatusChange |          1 | fk_ContactStatusChange_ChangeStateType1 |            1 | changeStateType          | A         |          18 |     NULL | NULL   |      | BTREE      |         |               |<br />
+---------------------+------------+-----------------------------------------+--------------+--------------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
<br />
 show index from jobCntrl.Job;<br />
+-------+------------+---------------------------+--------------+--------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| Table | Non_unique | Key_name                  | Seq_in_index | Column_name        | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br />
+-------+------------+---------------------------+--------------+--------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| Job   |          0 | PRIMARY                   |            1 | job_guid           | A         |         817 |     NULL | NULL   |      | BTREE      |         |               |<br />
| Job   |          1 | owner_identity            |            1 | ownerOfWork_id     | A         |          38 |     NULL | NULL   | YES  | BTREE      |         |               |<br />
| Job   |          1 | fk_Job_JobReasonType1_idx |            1 | jobCategoryType_id | A         |           8 |     NULL | NULL   |      | BTREE      |         |               |<br />
| Job   |          1 | fk_Job_JobType1_idx       |            1 | jobType_id         | A         |          10 |     NULL | NULL   |      | BTREE      |         |               |<br />
+-------+------------+---------------------------+--------------+--------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
4 rows in set (0.00 sec)<br />
<br />
<br />
<br />
 show index from webAcctTrans.client;<br />
+--------+------------+------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| Table  | Non_unique | Key_name         | Seq_in_index | Column_name      | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |<br />
+--------+------------+------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
| client |          0 | PRIMARY          |            1 | identity         | A         |      108185 |     NULL | NULL   |      | BTREE      |         |               |<br />
| client |          0 | screenName       |            1 | screenName       | A         |      108185 |     NULL | NULL   |      | BTREE      |         |               |<br />
| client |          0 | email_address    |            1 | email_address    | A         |      108185 |     NULL | NULL   |      | BTREE      |         |               |<br />
| client |          1 | account_identity |            1 | account_identity | A         |      108185 |     NULL | NULL   |      | BTREE      |         |               |<br />
+--------+------------+------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+<br />
4 rows in set (0.00 sec)<br />
<br />
<br />
THIS IS THE QUERU EXECUTION PLAN AS BELOW<br />
<br />
<br />
explain SELECT COUNT(1) AS removedItems, c.identity AS userId, c.email_address, DATE_FORMAT(sc.stateTs, '%m/%d/%Y') AS completedDate<br />
    -&gt; FROM changeList.ContactStatusChange sc JOIN jobCntrl.Job j ON sc.job_guid = j.job_guid LEFT JOIN webAcctTrans.client c ON j.authorClient_id = c.identity<br />
    -&gt; WHERE sc.changeStateType = 5 AND sc.createTs &gt; '2013-04-01 00:00:00' AND sc.createTs &lt; '2013-04-30 23:59:59'<br />
    -&gt; GROUP BY userId ORDER BY c.email_address asc;<br />
+----+-------------+-------+--------+----------------------------------------------------------------------------------------+-----------------------------------------+---------+----------------------------+----------+----------------------------------------------+<br />
| id | select_type | table | type   | possible_keys                                                                          | key                                     | key_len | ref                        | rows     | Extra                                        |<br />
+----+-------------+-------+--------+----------------------------------------------------------------------------------------+-----------------------------------------+---------+----------------------------+----------+----------------------------------------------+<br />
|  1 | SIMPLE      | sc    | ref    | changeDate,fk_personstagingAccuracyChange_Job1,fk_ContactStatusChange_ChangeStateType1 | fk_ContactStatusChange_ChangeStateType1 | 4       | const                      | 62765435 | Using where; Using temporary; Using filesort |<br />
|  1 | SIMPLE      | j     | eq_ref | PRIMARY                                                                                | PRIMARY                                 | 38      | changeList.sc.job_guid     |        1 |                                              |<br />
|  1 | SIMPLE      | c     | eq_ref | PRIMARY                                                                                | PRIMARY                                 | 4       | jobCntrl.j.authorClient_id |        1 |                                              |<br />
+----+-------------+-------+--------+----------------------------------------------------------------------------------------+-----------------------------------------+---------+----------------------------+----------+----------------------------------------------+<br />
3 rows in set (0.00 sec)<br />
<br />
<br />
<br />
Guy I need someone to help me making this query fast,<br />
Thanks in Advance]]></description>
            <dc:creator>himanshu patel</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 14 May 2013 14:51:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,584254,584254#msg-584254</guid>
            <title>Query Profiling inconsistence (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,584254,584254#msg-584254</link>
            <description><![CDATA[ I have a strange situation in my hands which I would like to know if someone can help me with.<br />
<br />
I have a stored procedure that calls some functions internally, if I call the functions separately they work perfectly, but when I call the main stored it gets very slow like 50 seconds to execute and sometimes it is normal like 2 seconds to execute, with exactly same parameters. I tried to run the profile in order to see what is happening and where it is getting stuck, but the profile result is not consistent with the reality, following an example of a weird result. As you can see the stored took 22 seconds to execute, but by the profile it should not take more than 1 second to execute. So can anyone tell me what is wrong here? <br />
<br />
mysql&gt; CALL relatorio_consumo_veiculo (4,'2013-04-12 00:00', '2013-04-12 23:59','3200', 3.00, 2.00, 'pt-BR');<br />
+---------+---------+-----------+---------+-----------+------------------+-----------------+------------------+-----------------+--------------------+----------------+------------------+----------------+-----------------+<br />
| _restag | _resnom | _objidsec | _objnom | _distperc | _consumocombreal | _kmporlitroreal | _consumocombespe | _kmporlitroespe | _desviocomsumocomb | _custoporlitro | _custodesviocomb | _custokmrodado | _desvioporcento |<br />
+---------+---------+-----------+---------+-----------+------------------+-----------------+------------------+-----------------+--------------------+----------------+------------------+----------------+-----------------+<br />
|         |         | 3200      | 3200    |       444 |              153 |         2.90196 |              148 |               3 |                  5 |              2 |               10 |       0.689189 |         3.37838 |<br />
+---------+---------+-----------+---------+-----------+------------------+-----------------+------------------+-----------------+--------------------+----------------+------------------+----------------+-----------------+<br />
1 row in set (22.59 sec)<br />
<br />
Query OK, 0 rows affected, 1 warning (15.59 sec)<br />
<br />
mysql&gt; SHOW profile;<br />
+---------------------------+----------+<br />
| Status                    | Duration |<br />
+---------------------------+----------+<br />
| continuing inside routine | 0.000034 |<br />
| Opening tables            | 0.000028 |<br />
| System lock               | 0.000025 |<br />
| Table lock                | 0.000026 |<br />
| init                      | 0.000040 |<br />
| optimizing                | 0.000032 |<br />
| statistics                | 0.000023 |<br />
| preparing                 | 0.000022 |<br />
| executing                 | 0.000019 |<br />
| Sending data              | 0.000183 |<br />
| end                       | 0.000029 |<br />
| query end                 | 0.000024 |<br />
| closing tables            | 0.000054 |<br />
+---------------------------+----------+<br />
13 rows in set (0.02 sec)<br />
<br />
mysql&gt; show profiles;<br />
+----------+------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+<br />
| Query_ID | Duration   | Query                                                                                                                                                                                                                                                                                                        |<br />
+----------+------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+<br />
|       73 | 0.00008300 | CREATE TEMPORARY TABLE IF NOT EXISTS itrax.consumo_veiclo_tmp_table(<br />
    _restag VARCHAR(20),<br />
    _resnom VARCHAR(100),<br />
    _objidsec VARCHAR(20),<br />
    _objnom VARCHAR(50),<br />
    _distperc FLOAT,<br />
    _consumocombreal FLOAT,<br />
    _kmporlitroreal FLOAT,<br />
    _consumocombespe FLOAT,<br />
    _kmporlitroespe FLOA |<br />
|       74 | 0.00020000 | DELETE FROM consumo_veiclo_tmp_table                                                                                                                                                                                                                                                                         |<br />
|       75 | 0.00033500 | SELECT pp.PONPERDISPER INTO _min_dist<br />
      FROM ponto_percorrido pp WHERE pp.VEIID=_objid AND pp.PONPERDATHOR<br />
      BETWEEN _date_ini AND _date_fim AND pp.PONPERVALID=1<br />
      ORDER BY pp.PONPERDATHOR LIMIT 1                                                                                            |<br />
|       76 | 0.00023500 | SELECT pp.PONPERDISPER INTO _max_dist<br />
      FROM ponto_percorrido pp WHERE pp.VEIID=_objid AND pp.PONPERDATHOR<br />
      BETWEEN _date_ini AND _date_fim AND pp.PONPERVALID=1<br />
      order by pp.PONPERDATHOR desc limit 1                                                                                       |<br />
|       77 | 0.00026600 | SELECT s.SENSORVALUE into _valor_min FROM sensor_valor s<br />
    INNER JOIN ponto_percorrido pp ON (s.PONPERIDENTIFY=pp.PONPERIDENTIFY)<br />
    WHERE pp.VEIID=_objid AND s.SENTYP=6 AND s.SENSORVALUE&gt;0 AND pp.PONPERDATHOR BETWEEN _data_ini AND _data_fim<br />
    order by pp.PONPERDATHOR limit 1                    |<br />
|       78 | 0.00038800 | SELECT s.SENSORVALUE INTO _valor_max FROM sensor_valor s<br />
    INNER JOIN ponto_percorrido pp ON (s.PONPERIDENTIFY=pp.PONPERIDENTIFY)<br />
    WHERE pp.VEIID=_objid AND s.SENTYP=6 AND s.SENSORVALUE&gt;0 AND pp.PONPERDATHOR BETWEEN _data_ini AND _data_fim<br />
    ORDER BY pp.PONPERDATHOR desc LIMIT 1               |<br />
|       79 | 0.00008100 | SELECT _distperc/_consumocombreal INTO _kmporlitroreal                                                                                                                                                                                                                                                       |<br />
|       80 | 0.00008100 | SELECT _distperc/_consumo_por_km_esperado INTO _consumocombespe                                                                                                                                                                                                                                              |<br />
|       81 | 0.00007400 | SELECT _consumocombreal-_consumocombespe INTO _desviocomsumocomb                                                                                                                                                                                                                                             |<br />
|       82 | 0.00007300 | SELECT _desviocomsumocomb*_valor_medio_litro_combus INTO _custodesviocomb                                                                                                                                                                                                                                    |<br />
|       83 | 0.00009700 | SELECT (_consumocombreal*_valor_medio_litro_combus)/_distperc INTO _custokmrodado                                                                                                                                                                                                                            |<br />
|       84 | 0.00007900 | SELECT (_desviocomsumocomb/_consumocombespe)*100 INTO _desvioporcento                                                                                                                                                                                                                                        |<br />
|       85 | 0.00014100 | insert into consumo_veiclo_tmp_table values(_restag,_resnom,_objidsec,_objnom,_distperc,_consumocombreal,_kmporlitroreal,_consumocombespe,_consumo_por_km_esperado,_desviocomsumocomb,_valor_medio_litro_combus,_custodesviocomb,_custokmrodado,_desvioporcento)                                             |<br />
|       86 | 0.00019200 | select * from consumo_veiclo_tmp_table]]></description>
            <dc:creator>Flavio Tobias</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 18 Apr 2013 16:02:22 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,583851,583851#msg-583851</guid>
            <title>How to trigger a query every minute (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,583851,583851#msg-583851</link>
            <description><![CDATA[ I have a system designed where I want a query to be triggered every minute to fetch necessary records from the database and perform certain actions.It would be a back end process and certain notifications would be sent to the concerned mail ids from the data fetched.<br />
<br />
Plz suggest how to proceed for the query.]]></description>
            <dc:creator>Rajesh Swain</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Sat, 13 Apr 2013 06:54:06 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,581946,581946#msg-581946</guid>
            <title>How to subtract 1 minute from time (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,581946,581946#msg-581946</link>
            <description><![CDATA[ Hi experts,<br />
<br />
I have a query contains from time and to time parameters.<br />
I need to subtract 1 minute from totime parameter.<br />
I used totime-1.<br />
It is working in database level and it is not working in my crystal reports.I mean it is subtracting 1 hour in report level.<br />
Can any one please tell me other formula for subtracting a minute.<br />
Please find the where condition in my query<br />
<br />
where<br />
ccsr.store_date = {?Transaction Date}<br />
and ccsr.value_type='B'<br />
and (cast(time_format(ccsr.transaction_time,'%H') as unsigned) between<br />
{?From Time} and ({?To Time}-1))<br />
group by<br />
ccsr.brand_code<br />
) cons<br />
<br />
<br />
<br />
<br />
Thanks in advance,<br />
divya]]></description>
            <dc:creator>divya vani</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Wed, 03 Apr 2013 14:39:57 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,581415,581415#msg-581415</guid>
            <title>Stored Procedure With XML Datas (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,581415,581415#msg-581415</link>
            <description><![CDATA[ Hi,<br />
<br />
Please let me know how to read the values from the below xml.<br />
<br />
set @xmlBooks = '<br />
&lt;Books Booksid=&quot;1&quot; code=&quot;20130212&quot;&gt;<br />
	&lt;category categoryid=&quot;1&quot; catcode=&quot;1000&quot; catgeoryname=&quot;Books1&quot;&gt;<br />
		&lt;item itemid=&quot;1&quot; itemcode=&quot;500001&quot; itemamount=&quot;500&quot; itemstatus=&quot;1&quot; categoryid=&quot;1&quot;&gt;<br />
<br />
		&lt;/item&gt;<br />
		&lt;item itemid=&quot;2&quot; itemcode=&quot;450001&quot; itemamount=&quot;300&quot; itemstatus=&quot;1&quot; categoryid=&quot;1&quot;&gt;<br />
<br />
		&lt;/item&gt;<br />
	&lt;/category&gt;<br />
	&lt;category categoryid=&quot;2&quot; catcode=&quot;3450&quot; catgeoryname=&quot;Books2&quot;&gt;<br />
		&lt;item itemid=&quot;1&quot; itemcode=&quot;25001&quot; itemamount=&quot;450&quot; itemstatus=&quot;1&quot; categoryid=&quot;2&quot;&gt;<br />
<br />
		&lt;/item&gt;<br />
		&lt;item itemid=&quot;2&quot; itemcode=&quot;35001&quot; itemamount=&quot;250&quot; itemstatus=&quot;1&quot; categoryid=&quot;2&quot;&gt;<br />
<br />
		&lt;/item&gt;<br />
	&lt;/category&gt;<br />
&lt;/Books&gt;';<br />
<br />
Here Category and Item will be dynamically. I want to read the each category and item values one by one. I need this code in Stored Procedure.<br />
<br />
I have done the code to find the category as below<br />
DECLARE CCount INT;<br />
DECLARE rowNum INT DEFAULT 1;<br />
<br />
SET CCount= extractvalue(xmlBooks, 'count(//category)');<br />
WHILE rowNum &lt;= CCount DO<br />
<br />
SELECT<br />
      extractvalue(xmlBooks , '//child::*[$rowNum]/@categoryid'),<br />
      extractvalue(xmlBooks , '//child::*[$rowNum]/@catcode'),<br />
      extractvalue(xmlBooks , '//child::*[$rowNum]/@catgeoryname');<br />
<br />
SET rowNum = rowNum + 1;<br />
END WHILE;<br />
<br />
<br />
Thanks,<br />
Senthil.]]></description>
            <dc:creator>Senthil V</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 15 Mar 2013 09:27:30 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,580503,580503#msg-580503</guid>
            <title>How to use table alias in select (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,580503,580503#msg-580503</link>
            <description><![CDATA[ Hello all,<br />
<br />
I have a query given below:<br />
<br />
SELECT A,<br />
       B,<br />
      ( SELECT C <br />
        FROM test2 t2 <br />
        WHERE t.A = t2.A<br />
        ORDER BY A DESC LIMIT 1<br />
      ) <br />
<br />
     FROM <br />
     Test t<br />
<br />
I am using mysql yog from executing this query. It is causing an error. Please let me know the correct implementation of this query.<br />
<br />
Thanks in advance]]></description>
            <dc:creator>Pankaj Kumar</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Mon, 04 Mar 2013 06:14:34 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,580091,580091#msg-580091</guid>
            <title>Query Performance (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,580091,580091#msg-580091</link>
            <description><![CDATA[ I am having difficulty figuring out how to improve the performance of a query.  The query is used to obtain a summary of individuals from a family tree database based upon their names.  Note that each individual may have more than one name.  For example a married person has both a birth name and a married name (which may be the same).  A person may also have an adopted name, or a nom de plume, etc.<br />
<br />
<pre class="bbcode">
SELECT DISTINCT tblNX.IDIR, tblNX.Surname,
			  tblIR.Surname, tblNX.GivenName,
			  tblIR.BirthD, tblIR.DeathD, tblIR.Gender
			FROM tblNX JOIN tblIR on tblIR.IDIR=tblNX.IDIR
			WHERE ((tblNX.Surname='Campbell' AND 
			                         tblNX.GivenName&gt;='John') OR
			             tblNX.Surname&gt;'Campbell') AND
                                                  tblNX.`Order`&gt;=0 
			ORDER BY tblNX.SurName, tblNX.GivenName,
				 tblIR.BirthSD, tblIR.DeathSD LIMIT 50</pre>
<br />
The table containing the basic data on the individual is tblIR:<br />
<br />
<pre class="bbcode">
CREATE TABLE `tblIR` ( 
  `ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
  `IDIR` INT(10) UNSIGNED DEFAULT NULL, 
  `FSID` VARCHAR(255) DEFAULT NULL, 
  `Surname` VARCHAR(120) DEFAULT NULL, 
  `SoundsLike` VARCHAR(4) DEFAULT NULL, 
  `GivenName` VARCHAR(120) DEFAULT NULL, 
  `Prefix` VARCHAR(120) DEFAULT NULL, 
  `Title` VARCHAR(120) DEFAULT NULL, 
  `NameNote` LONGTEXT, 
  `Gender` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, 
  `BirthD` VARCHAR(100) DEFAULT NULL, 
  `BirthSD` INT(10) NOT NULL DEFAULT -99999999, 
  `IDLRBirth` INT(10) UNSIGNED DEFAULT NULL, 
  `ChrisD` VARCHAR(100) DEFAULT NULL, 
  `ChrisSD` INT(10) NOT NULL DEFAULT -99999999, 
  `IDLRChris` INT(10) UNSIGNED DEFAULT NULL, 
  `ChrTerm` VARCHAR(100) DEFAULT NULL, 
  `DeathD` VARCHAR(100) DEFAULT NULL, 
  `DeathSD` INT(10) NOT NULL DEFAULT -99999999, 
  `IDLRDeath` INT(10) UNSIGNED DEFAULT NULL, 
  `BuriedD` VARCHAR(100) DEFAULT NULL, 
  `BuriedSD` INT(10) NOT NULL DEFAULT -99999999, 
  `IDLRBuried` INT(10) UNSIGNED DEFAULT NULL, 
  ...
  PRIMARY KEY (`ID`), 
  UNIQUE KEY `IDIR` (`IDIR`), 
  KEY `Surname` (`Surname`), 
  KEY `GivenName` (`GivenName`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8</pre>
<br />
The nominal index, which includes all of the alternative names, is in table tblNX:<br />
<pre class="bbcode">
CREATE TABLE `tblNX` ( 
  `IDNX` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
  `IDNR` INT(10) UNSIGNED DEFAULT NULL, 
  `IDIR` INT(10) UNSIGNED DEFAULT NULL, 
  `Order` smallint(5) NOT NULL DEFAULT 0, 
  `MarriedNameCreatedBy` TINYINT(3) UNSIGNED DEFAULT NULL, 
  `MarriedNameMarIDID` INT(10) UNSIGNED DEFAULT NULL, 
  `Prefix` VARCHAR(120) DEFAULT NULL, 
  `Title` VARCHAR(120) DEFAULT NULL, 
  `Surname` VARCHAR(120) NOT NULL DEFAULT '', 
  `GivenName` VARCHAR(120) NOT NULL DEFAULT '', 
  `SoundsLike` VARCHAR(4) NOT NULL DEFAULT '', 
  `UserRef` VARCHAR(50) DEFAULT NULL, 
  `AKANote` LONGTEXT, 
  `PreferredAKA` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, 
  `BirthSD` INT(10) NOT NULL DEFAULT -99999999, 
  `SrchTag` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, 
  `qsTag` TINYINT(3) UNSIGNED NOT NULL DEFAULT 0, 
  PRIMARY KEY (`IDNX`), 
  KEY `IDIR` (`IDIR`), 
  KEY `Surname` (`Surname`), 
  KEY `GivenName` (`GivenName`), 
  KEY `SoundsLike` (`SoundsLike`), 
) ENGINE=MyISAM DEFAULT CHARSET=utf8</pre>
problem<br />
Explain on this query returns:<br />
<pre class="bbcode">
+----+-------------+-------+------+------------------------+------+---------+------------------------------+-------+---------------------------------+
| id | select_type | table | type | possible_keys          | key  | key_len | ref                          | rows  | Extra                           |
+----+-------------+-------+------+------------------------+------+---------+------------------------------+-------+---------------------------------+
|  1 | SIMPLE      | tblIR | ALL  | IDIR                   | NULL | NULL    | NULL                         | 67863 | Using temporary; Using filesort |
|  1 | SIMPLE      | tblNX | ref  | IDIR,Surname,GivenName | IDIR | 5       | jcobban_genealogy.tblIR.IDIR |     1 | Using where                     |
+----+-------------+-------+------+------------------------+------+---------+------------------------------+-------+---------------------------------+</pre>
As I understand this, the server is performing a linear search of the entire table tblIR, which currently has 67863 rows, and then uses IDIR to examine the associated rows of tblNX.  This has poor performance and will only get worse as more rows are added.  I do not understand why the primary search is not on tblNX, which is the only table referenced in the WHERE clause, or why the key of tblIR, which is explicitly mentioned in the JOIN, is not being used.<br />
<br />
If I extract the core of the query I get:<br />
<pre class="bbcode">
explain select idir, surname, givenname from tblNX where ((surname='Campbell' and givenname&gt;='John') or surname&gt;'Campbell') order by surname, givenname, birthsd limit 20;
+----+-------------+-------+-------+-------------------+---------+---------+------+-------+-----------------------------+
| id | select_type | table | type  | possible_keys     | key     | key_len | ref  | rows  | Extra                       |
+----+-------------+-------+-------+-------------------+---------+---------+------+-------+-----------------------------+
|  1 | SIMPLE      | tblNX | range | Surname,GivenName | Surname | 363     | NULL | 78515 | Using where; Using filesort |
+----+-------------+-------+-------+-------------------+---------+---------+------+-------+-----------------------------+
1 row in set (0.00 sec)</pre>
This does show the query exploiting the surname index, although not the given name index.  The performance of this query is probably acceptable.  The problem is that while tblNX contains all of the name information it does not contain the &quot;maiden&quot; surname, gender, birth date, and death date information which I need to display to the end user, which is why I did the join of tblIR.<br />
<br />
How do I restructure this query to get MySQL to do the tblNX query exploiting the surname index and then join the tblIR information into the response?]]></description>
            <dc:creator>James Cobban</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 26 Feb 2013 23:19:19 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,578650,578650#msg-578650</guid>
            <title>Select Last Distinct record (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,578650,578650#msg-578650</link>
            <description><![CDATA[ i have a table with three fields<br />
id,bank_id,amount<br />
<br />
it has alot of data....how i can select last entry for all distinct banks ?<br />
lets say(Below code has not tested,it is from sqlserver)<br />
IF OBJECT_ID('TempDB..#mytable1','U') IS NOT NULL<br />
DROP TABLE #mytable1<br />
CREATE TABLE #mytable1<br />
(<br />
Id INT IDENTITY(1,1) primary key,<br />
bank_id INT,<br />
amount BIGINT<br />
)<br />
<br />
INSERT INTO #mytable1<br />
(bank_id,amount )<br />
SELECT 1,'2000' UNION ALL<br />
SELECT 2,'1000' UNION ALL<br />
SELECT 3,'6000' UNION ALL<br />
SELECT 2,'100' UNION ALL<br />
SELECT 2,'500' UNION ALL<br />
SELECT 1,'900';<br />
<br />
i need this result<br />
bank_id          amount<br />
1              900<br />
2              500<br />
3               6000]]></description>
            <dc:creator>Moh Methew</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 07 Feb 2013 08:19:44 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,577522,577522#msg-577522</guid>
            <title>Query with duplicate key (URGENT) (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,577522,577522#msg-577522</link>
            <description><![CDATA[ Hi,<br />
i have a DB called &quot;csv_db&quot; with a tbale called &quot;reportinc&quot;.<br />
The tabale have this column:<br />
<br />
`ID incidente`, `Aperto da`, `Stato`, `Categoria`, `Area`, `Sottoarea`, `Titolo`, `Priorità`, `Data/ora apertura`, `Data/Ora risoluzione`, `Data/ora chiusura`, `Inizio Interruzione di servizio`, `Fine interruzione di servizio`, `Conteggio riassegnazioni`, `Gruppo di assegnazione`, `Assegnatario`, `Risolto da`, `Gruppo risoluzione`, `Chiuso da`, `Gruppo di chiusura`, `ID interazione`, `Id Remedy`, `Descrizione`, `Soluzione`, `Servizio Interessato`, `Servizi Interessati`, `CI interessato`, `CI operativo`, `Ultimo aggiornamento da`<br />
<br />
The primary and unique key  is `ID incidente`<br />
<br />
I need to import each day from .CSV (comma separated) and:<br />
<br />
1) Inseret new rows with new value (`ID incidente` also)<br />
2) Update existing rows in the list.<br />
<br />
I tried a query smilar to:<br />
<br />
LOAD DATA LOCAL INFILE 'd:\export.csv'<br />
INSERT INTO `reportinc` (`ID incidente`, `Aperto da`, `Stato`, `Categoria`, `Area`, `Sottoarea`, `Titolo`, `Priorità`, `Data/ora apertura`, `Data/Ora risoluzione`, `Data/ora chiusura`, `Inizio Interruzione di servizio`, `Fine interruzione di servizio`, `Conteggio riassegnazioni`, `Gruppo di assegnazione`, `Assegnatario`, `Risolto da`, `Gruppo risoluzione`, `Chiuso da`, `Gruppo di chiusura`, `ID interazione`, `Id Remedy`, `Descrizione`, `Soluzione`, `Servizio Interessato`, `Servizi Interessati`, `CI interessato`, `CI operativo`, `Ultimo aggiornamento da`) VALUES ($ID incidente, $Aperto da, $Stato, $Categoria, $Area, $Sottoarea, $Titolo, $Priorità, $Data/ora apertura, $Data/Ora risoluzione, $Data/ora chiusura, $Inizio Interruzione di servizio, $Fine interruzione di servizio, $Conteggio riassegnazioni, $Gruppo di assegnazione, $Assegnatario, $Risolto da, $Gruppo risoluzione, $Chiuso da, $Gruppo di chiusura, $ID interazione, $Id Remedy, $Descrizione, $Soluzione, $Servizio Interessato, $Servizi Interessati, $CI interessato, $CI operativo, $Ultimo aggiornamento da)<br />
  ON DUPLICATE KEY UPDATE active = 1<br />
<br />
<br />
But i snot working.<br />
I need to update rows if duplicate, and NOT append.<br />
<br />
How to?<br />
Please me me (newbie)<br />
<br />
Thanks in advance.]]></description>
            <dc:creator>Simone Messina</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 18 Jan 2013 08:02:17 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,577479,577479#msg-577479</guid>
            <title>Tuning help with OR and UNION (2 replies)</title>
            <link>http://forums.mysql.com/read.php?166,577479,577479#msg-577479</link>
            <description><![CDATA[ I have a slow query that I'm trying to tune and am hoping someone might be able to assit. It is a 2rd party product so I can't change the query.<br />
<br />
SELECT * <br />
FROM `jobs` <br />
WHERE (<br />
       (jobs.pre = 1 OR jobs.post = 1) <br />
       AND DATE_ADD(UTC_TIMESTAMP(), INTERVAL -10800 SECOND) &gt; jobs.updated_at<br />
      )  <br />
ORDER BY jobs.priority DESC, jobs.created_at ASC <br />
LIMIT 20;<br />
<br />
The columns pre and post are almost always 0. I tried an index on updated_at, and it uses it but still select almost half the rows to perform the query, so it is just as slow as the full table scan. I then tried adding indexes on many combinations of update_at/pre/post, pre, post, pre/post, etc. Even with &quot;force index&quot; no luck. Given the highly skewed data, pre and post seem optimal, so...<br />
<br />
I then created an index on pre and another on post and wrote the query this way:<br />
<br />
SELECT * <br />
FROM `jobs` <br />
WHERE jobs.pre = 1 AND DATE_ADD(UTC_TIMESTAMP(), INTERVAL -10800 SECOND) &gt; jobs.updated_at <br />
union <br />
SELECT * <br />
FROM `jobs` <br />
WHERE jobs.post = 1 AND DATE_ADD(UTC_TIMESTAMP(), INTERVAL -10800 SECOND) &gt; jobs.updated_at <br />
ORDER BY priority DESC, created_at ASC LIMIT 20;<br />
<br />
This uses both indexes and retrieves only 1 row per query. Very, very fast.<br />
<br />
Is there a way I can convince the originall query to work as it does in the union form?]]></description>
            <dc:creator>Jed Walker</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 17 Jan 2013 17:23:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,577191,577191#msg-577191</guid>
            <title>Enum or its Equivalent in mysql!! (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,577191,577191#msg-577191</link>
            <description><![CDATA[ Hi,<br />
I have one table in my mysql database, where one of the fields is Country. I am in process of developing GEO tracking system where users who upload the video will have the facility to restrict (like allow/deny) the video for any country. <br />
<br />
Since there are so many countries, Is there any possibility that whenever someone uploads a video and selects a country to allow/deny the video from a particular GEO location, the country gets automatically added to the database.<br />
<br />
The catch here is, If a user selects more that one country to allow/deny, I do not want more than one entry about the country in my database table.<br />
<br />
So I was looking out for a solution in Enum. If I can create a column (as country) which can takes care of multiple values all dynamically, one of my purpose will be resolved. Something like:<br />
<br />
user_id   Country        Video_Id   type<br />
1          Ind,Pak,GB     20145      Allow<br />
2          Ind,USA        20176      Deny<br />
<br />
Also, If I want to search the Countries on the basis on the basis of either type/Video_ID, I should get the complete set of Country List.<br />
<br />
Your Help is appreciated!!<br />
<br />
Thanks]]></description>
            <dc:creator>Tarun Gurmukhani</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 17 Jan 2013 21:43:23 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,577190,577190#msg-577190</guid>
            <title>Query Optimization (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,577190,577190#msg-577190</link>
            <description><![CDATA[ Hi,<br />
I have a query, which is being used at 10 places. Per query it is taking around 5-6 Ms to execute and generate the result.<br />
Only Id(One of the fields in the query/database) is getting changed (dynamically), but rest all of the parameters are same.<br />
Can someone please throw some insight if I can optimize the complete set (all 10) so that total execution for all the 10 queries can be reduced to 10 Ms. <br />
<br />
Your help is appreciated!!<br />
<br />
Thanks]]></description>
            <dc:creator>Tarun Gurmukhani</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 11 Jan 2013 07:27:48 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,577128,577128#msg-577128</guid>
            <title>Need help! To find the query for my task (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,577128,577128#msg-577128</link>
            <description><![CDATA[ I need your help to finish my task at the office. I've confused to find the query to select the name from the unit. below is my table looks like:<br />
<br />
table unit<br />
unit_id|unit_name|parent_id<br />
1      |Head     | 0<br />
2      |Body     | 1<br />
3      |Hand     | 1<br />
4      |Eye      | 1<br />
<br />
table employee<br />
employee_id|employee_name|unit_id<br />
1          |John         | 2<br />
2          |Blair        | 3<br />
3          |Blade        | 4<br />
4          |Javier       | 2<br />
<br />
I want to select the parent unit_name. and the output is look like these:<br />
<br />
employee_id|employee_name|unit_id|parent_name<br />
1          |John         | 2     |Head<br />
2          |Blair        | 3     |Head<br />
3          |Blade        | 4     |Head<br />
4          |Javier       | 2     |Head]]></description>
            <dc:creator>Ruin Dash</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 10 Jan 2013 03:23:13 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,576025,576025#msg-576025</guid>
            <title>print all columns for where datetime=max(datetime) group by date(datetime) in Mysql (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,576025,576025#msg-576025</link>
            <description><![CDATA[ I have problem in selecting other columns for the max(datetime) records. In layman terms I need to get max(DialDateTime) records for all the dates in Mysql.<br />
<br />
 mysql&gt; select max(DialDateTime) as max from log_AP group by   date(DialDateTime) ;<br />
 +---------------------+<br />
 | max                 |<br />
 +---------------------+<br />
 | 2012-12-03 07:37:26 | <br />
 | 2012-12-04 07:37:04 | <br />
 | 2012-12-05 07:37:04 | <br />
 | 2012-12-06 07:37:04 | <br />
 | 2012-12-07 07:37:04 | <br />
 | 2012-12-08 07:37:04 | <br />
 | 2012-12-09 07:37:04 | <br />
 +---------------------+]]></description>
            <dc:creator>Mannoj Kumar</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 13 Dec 2012 14:00:53 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,575892,575892#msg-575892</guid>
            <title>Finding loop in indexes (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,575892,575892#msg-575892</link>
            <description><![CDATA[ A simple query<br />
Update Table1 set col1 = 12 where col2='13' which is taking long long time like 4 or more minutes even though table has less than 100 rows.<br />
Memory consumption - 99%<br />
CPU - 20%<br />
However, table has so many joins with other tables, indexes, foreign keys, etc. All tables are so interrelated like x is connected to y and then y connected to z and then z comes back to x.<br />
<br />
So how could I check that it is forming a loop while doing update or some lock problems.]]></description>
            <dc:creator>Seema Bhatia</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 11 Dec 2012 23:11:19 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,575891,575891#msg-575891</guid>
            <title>search criteria - int datatype (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,575891,575891#msg-575891</link>
            <description><![CDATA[ Query - col1 and col2 are both int<br />
col2 is primary<br />
col1 also has non clustered index<br />
1) update table1 set col1 = 12 where col2 = '13'<br />
<br />
2) update table1 set col1 = '12' where col2 = 13<br />
<br />
How these queries will behave?<br />
Are there performance issues as numbers are enclosed in quotes.<br />
<br />
I know at mysql will do implicit conversion. Will it take benefit of indexes in both the queries.]]></description>
            <dc:creator>Seema Bhatia</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 11 Dec 2012 23:11:41 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,575742,575742#msg-575742</guid>
            <title>select query with ident_current function to retreive the last inserted record. (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,575742,575742#msg-575742</link>
            <description><![CDATA[ Hello Friends,<br />
<br />
I am working on .net application. For database previously I was using MS SQL, But nowadays as per requirement, I am using the mysql. <br />
<br />
While working with MS SQL, I had used indent_Current function to retrieve the last insert record id &quot;(SELECT IDENT_CURRENT('country') As Country_Uid)&quot;. But in Mysql it gives me error.. I tried to found on google but didtnt get the solution. Please help me. Any reply are highly appreciated.<br />
<br />
Thanks in advance.]]></description>
            <dc:creator>priya sarin</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 11 Dec 2012 23:12:02 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,575296,575296#msg-575296</guid>
            <title>Need a little help with this query (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,575296,575296#msg-575296</link>
            <description><![CDATA[ I am trying to edit this report to include the product sell price. I am a novice at MySQL so if any users familiar would help that would be great!<br />
I am trying to get the actual discount amount given from individual sales and I believe that I can get it by subtracting the ticketline.price from the product.pricesell for each row to get the actual discount amount, and then sum up the total discount. How would I join the product.pricesell of the item to this code?<br />
report = new com.openbravo.pos.reports.PanelReportBean();<br />
report.setTitleKey(&quot;Menu.SalesByCustomer&quot;);<br />
report.setReport(&quot;/com/openbravo/reports/salebycustomer&quot;);<br />
report.setResourceBundle(&quot;com/openbravo/reports/salebycustomer_messages&quot;);<br />
report.setSentence(&quot;SELECT &quot; +<br />
&quot;PEOPLE.NAME AS CNAME, &quot; +<br />
&quot;RECEIPTS.DATENEW, &quot; +<br />
&quot;TICKETS.TICKETID, &quot; +<br />
&quot;PRODUCTS.NAME AS PNAME, &quot; + <br />
&quot;TICKETS.TICKETTYPE, &quot; +<br />
&quot;SUM(TICKETLINES.UNITS) AS UNITS, &quot; +<br />
&quot;SUM(TICKETLINES.UNITS * TICKETLINES.PRICE) AS TOTAL &quot; +<br />
&quot;FROM RECEIPTS, PEOPLE, TICKETS, TICKETLINES LEFT OUTER JOIN PRODUCTS ON TICKETLINES.PRODUCT = PRODUCTS.ID &quot; +<br />
&quot;WHERE PEOPLE.ID = TICKETS.PERSON AND TICKETLINES.PRODUCT = PRODUCTS.ID AND RECEIPTS.ID = TICKETS.ID AND TICKETS.ID = TICKETLINES.TICKET AND ?(QBF_FILTER) &quot; +<br />
&quot;GROUP BY PEOPLE.NAME, RECEIPTS.DATENEW, TICKETS.TICKETID, PRODUCTS.NAME, TICKETS.TICKETTYPE &quot; +<br />
&quot;ORDER BY PEOPLE.NAME, PRODUCTS.NAME, RECEIPTS.DATENEW&quot;);<br />
report.addParameter(&quot;RECEIPTS.DATENEW&quot;);<br />
report.addParameter(&quot;RECEIPTS.DATENEW&quot;);<br />
paramdates = new com.openbravo.pos.reports.JParamsDatesInterval();<br />
paramdates.setEndDate(com.openbravo.beans.DateUtils.getToday());<br />
report.addQBFFilter(paramdates);<br />
report.addField(&quot;CNAME&quot;, com.openbravo.data.loader.Datas.STRING);<br />
report.addField(&quot;DATENEW&quot;, com.openbravo.data.loader.Datas.TIMESTAMP);<br />
report.addField(&quot;TICKETID&quot;, com.openbravo.data.loader.Datas.STRING);<br />
report.addField(&quot;PNAME&quot;, com.openbravo.data.loader.Datas.STRING);<br />
report.addField(&quot;TICKETTYPE&quot;, com.openbravo.data.loader.Datas.INT);<br />
report.addField(&quot;UNITS&quot;, com.openbravo.data.loader.Datas.DOUBLE);<br />
report.addField(&quot;TOTAL&quot;, com.openbravo.data.loader.Datas.DOUBLE);<br />
report;]]></description>
            <dc:creator>Amardulguun Sandag</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Wed, 05 Dec 2012 04:00:54 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,575237,575237#msg-575237</guid>
            <title>Help :Is this Query right? How to Get the Result: Which to use union OR join AND How? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,575237,575237#msg-575237</link>
            <description><![CDATA[ Can you please help me?<br />
<br />
QUERY1:<br />
<br />
SELECT COUNT(T1.ID) AS T1_COUNT,createdtime AS T1_TIME FROM TABLE_1 AS T1,TABLE_2 AS T2 WHERE T2.ID=T1.ID AND T1.STATE != 'C' AND T1.TIME BETWEEN '2010-01-01 00:00:00' AND '2010-09-25 23:59:59' AND PRTY='F' GROUP BY createdtime ORDER BY T1_TIME DESC<br />
<br />
GETTING RESULT:<br />
T1_COUNT ---------- T1_TIME<br />
3 ---------------- 2010-09-25<br />
4 ---------------- 2010-09-18<br />
2 ---------------- 2010-09-11<br />
<br />
QUERY2:<br />
<br />
SELECT COUNT(T1.ID) AS T2_COUNT,createdtime AS T2_TIME FROM TABLE_1 AS T1,TABLE_2 AS T2 WHERE T2.ID=T1.ID AND T1.STATE != 'C' AND T1.STATE ='E' AND T1.TIME BETWEEN '2010-01-01 00:00:00' AND '2010-09-25 23:59:59' AND PRTY='F' GROUP BY createdtime ORDER BY T2_TIME DESC<br />
<br />
GETTING RESULT:<br />
T2_COUNT ---------------- T2_TIME<br />
1 ---------------- 2010-09-25<br />
2 ---------------- 2010-09-18<br />
<br />
Sample Query:<br />
SELECT * FROM (<br />
SELECT COUNT(T1.ID) AS T1_COUNT,createdtime AS T1_TIME FROM TABLE_1 AS T1,TABLE_2 AS T2 WHERE T2.ID=T1.ID AND T1.STATE != 'C' AND T1.TIME BETWEEN '2010-01-01 00:00:00' AND '2010-09-25 23:59:59' AND PRTY='F' GROUP BY createdtime<br />
UNION<br />
SELECT COUNT(T1.ID) AS T2_COUNT,createdtime AS T2_TIME FROM TABLE_1 AS T1,TABLE_2 AS T2 WHERE T2.ID=T1.ID AND T1.STATE != 'C' AND T1.STATE ='E' AND T1.TIME BETWEEN '2010-01-01 00:00:00' AND '2010-09-25 23:59:59' AND PRTY='F' GROUP BY createdtime AS inLineView ORDER BY T1_TIME DESC<br />
<br />
RESULT:<br />
T1_COUNT ---------- T1_TIME<br />
1 ---------------- 2010-09-25<br />
3 ---------------- 2010-09-25<br />
2 ---------------- 2010-09-18<br />
4 ---------------- 2010-09-18<br />
2 ---------------- 2010-09-11<br />
(Please Give me idea or correct the sample Query to get Result like follows)<br />
NEEDED RESULT:<br />
T1_COUNT ----- T1_TIME ------ T2_COUNT ------ T2_TIME<br />
1 ------------- 2010-09-25 ----- 3 ----------- 2010-09-25<br />
2 ------------- 2010-09-18 ----- 4 ----------- 2010-09-18<br />
2 ------------- 2010-09-11]]></description>
            <dc:creator>Vinod sl</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 04 Dec 2012 13:27:28 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,574628,574628#msg-574628</guid>
            <title>partition in the table (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,574628,574628#msg-574628</link>
            <description><![CDATA[ Hello,<br />
<br />
I want to create a table in which data is store in partition as well as sub-partition.<br />
<br />
Suppose I want to insert the data under the partition (P_name) of the table. If partition is already exist then insert the data under this partition otherwise create the partition and then insert the data.<br />
<br />
Can you please help me on the same problem for sub-partition.<br />
<br />
Thanks in advance.]]></description>
            <dc:creator>sumit vedi</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 04 Dec 2012 13:28:30 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,573555,573555#msg-573555</guid>
            <title>return 0 (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,573555,573555#msg-573555</link>
            <description><![CDATA[ I am trying to return all portfolios, even if they don not have any that have NEWBIZ (return 0 with portfolio).  I tried IFNULL.  Not sure how to go about it.  Any advice?<br />
<pre class="bbcode">
select ifnull(count(*),0) ,d.portfolio from dbase d, portfolios pf where statusname='NEWBIZ'
and pf.portfolio=d.portfolio 
group by pf.portfolio order by pf.placementdate;
<pre class="bbcode"></pre></pre>]]></description>
            <dc:creator>Kelly Brace</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 04 Dec 2012 13:27:55 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,573318,573318#msg-573318</guid>
            <title>MySql Cache Dependency (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,573318,573318#msg-573318</link>
            <description><![CDATA[ Hello,<br />
<br />
In my project we developed cache on a table from php side, currently, the cache is update for every 1min even though, there is no updates on that table. So, my requirment is to update cache only when there is update on that table. Its like Sql Cache Dependency, but i din't find anywhere Sql Cache Dependency in mysql.Please help me how do Sql Cache Dependency in mysql.]]></description>
            <dc:creator>sagar pavan</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 09 Nov 2012 06:09:52 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,572917,572917#msg-572917</guid>
            <title>How to get query plan for a query using mysql command line tool (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,572917,572917#msg-572917</link>
            <description><![CDATA[ I am using mysql command line client, which comes along mysql 5.5 installer in windows. I want to check how my query is executed, where its spending time e.g. something like query plan available in SQL Server. Is there way I can see using mysql command line client ? <br />
<br />
Thanks]]></description>
            <dc:creator>Javin Paul</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Sun, 04 Nov 2012 05:42:25 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,572403,572403#msg-572403</guid>
            <title>Complex queries (no replies)</title>
            <link>http://forums.mysql.com/read.php?166,572403,572403#msg-572403</link>
            <description><![CDATA[ I have a database made by three tables: athlets, competitions and results, with following colums:<br />
<br />
- athlets (id, name)<br />
- competitions (id, name, date)<br />
- results (place, id_athlets, id_competition, ranking_points)<br />
<br />
with following relationships: <br />
- results.id_couple=athlets.id; <br />
- results.id_competition=competitions.id<br />
<br />
I need to make a query wich give the lastest (by competitions.date) ranking_points for each athlets.id]]></description>
            <dc:creator>Marian Nedelcu</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Mon, 29 Oct 2012 11:15:22 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,572363,572363#msg-572363</guid>
            <title>create table from multiple tables (3 replies)</title>
            <link>http://forums.mysql.com/read.php?166,572363,572363#msg-572363</link>
            <description><![CDATA[ I'm sorry I just realized I didn't explain what I was trying to do. <br />
<br />
I'm trying to create a report procedure. I created a report table, liqReports and I need columns/data from 3 other tables. This is what I have done, it's wrong. When I run the 3 selects alone, I get the correct data. I thought I could just do 3 inserts, then I thought I could do updates. Please advise.<br />
 <br />
<br />
-- --------------------------------------------------------------------------------<br />
-- Routine DDL<br />
-- Note: comments before and after the routine body will not be stored by the server<br />
-- --------------------------------------------------------------------------------<br />
DELIMITER $$<br />
<br />
CREATE DEFINER=`root`@`%` PROCEDURE `liqReport`()<br />
BEGIN<br />
truncate table liqReports;<br />
create table if not exists liqReports (face_amt decimal(12,2), pending_amt decimal(12,2), posted_amt decimal(12,2), portfolio_name varchar(24),place_date date);<br />
<br />
<br />
insert into liqReports(face_amt, pending_amt, posted_amt, portfolio_name, place_date)<br />
select 0, 0, sum(p.paymentamount), pf.portfolio, pf.placementdate from payments p,portfolios pf where p.portfolio=pf.portfolio and p.paymentstatus='POSTED' <br />
group by pf.portfolio order by pf.placementdate;<br />
<br />
<br />
update liqReports set pending_amt=(<br />
select sum(p.paymentamount) from payments p,liqReports lr where p.portfolio=lr.portfolio_name and p.paymentstatus='PENDING' <br />
group by lr.portfolio_name order by lr.place_date);<br />
<br />
<br />
insert into liqReports(face_amt, pending_amt, posted_amt, portfolio_name, place_date)<br />
select sum(d.originalbalance), lr.pending_amt, lr.posted_amt, lr.portfolio_name, lr.place_date from dbase d,liqReports lr where d.portfolio=lr.portfolio_name <br />
group by lr.portfolio_name order by lr.place_date;<br />
<br />
<br />
END]]></description>
            <dc:creator>Kelly Brace</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Tue, 04 Dec 2012 13:28:44 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,572233,572233#msg-572233</guid>
            <title>How to convert a Longblob to varchar? (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,572233,572233#msg-572233</link>
            <description><![CDATA[ Hi,<br />
Can anyone please let me know where i am going wrong with the below query?<br />
<br />
select * from openquery(MYSQL_LINKED, 'select<br />
t.Id as Ticket_id,<br />
max(tr.Created),<br />
cast(a.content as varchar(50)) as Attachment_content,<br />
oc.ObjectType,<br />
oc.Content as ObjectCF_content<br />
from rt.Tickets t<br />
inner join rt.Transactions tr on tr.ObjectId = t.Id<br />
inner join rt.Attachments a on  a.TransactionId = tr.Id<br />
inner join rt.Users u on u.Id = a.Creator<br />
inner join rt.ObjectCustomFieldValues oc on oc.ObjectId = tr.ObjectId<br />
where Status in (&quot;pending&quot;,&quot;open&quot;,&quot;new&quot;)<br />
and a.Content not like &quot;%WordDocument%&quot;<br />
and a.Content not like &quot;%word%&quot; and a.Content not like &quot;%div%&quot;<br />
and a.Content not like &quot;%http%&quot;<br />
and oc.CustomField in (&quot;2&quot;,&quot;17&quot;)<br />
and t.Id = &quot;6179&quot;')<br />
<br />
I get below error:<br />
OLE DB provider &quot;MSDASQL&quot; for linked server &quot;MYSQL_LINKED&quot; returned message &quot;[MySQL][ODBC 5.2(w) Driver][mysqld-5.0.92-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'utf-8) as Attachment_content,<br />
(a.Id) as Attachement_Id,<br />
(a.TransactionId),<br />
a.' at line 14&quot;.<br />
Msg 7350, Level 16, State 2, Line 2<br />
Cannot get the column information from OLE DB provider &quot;MSDASQL&quot; for linked server &quot;MYSQL_LINKED&quot;.<br />
<br />
Thanks!!]]></description>
            <dc:creator>radhika rao</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 26 Oct 2012 20:09:19 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,572186,572186#msg-572186</guid>
            <title>Update table from one database with data from another database (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,572186,572186#msg-572186</link>
            <description><![CDATA[ Hello I have 2 MySQL databases on the same server with same structure and same data. Occasionally data in one database are changed for 7 days and then should be back to the same value as in first database. Through PhpMyAdmin I am trying to write statement that should do thi but something I am missing. I have databases: db1_local and db2_local Table gitem column gbaseprice (should be synchronized from db1 to db2) column gitemcode (has same value in both databases and synchronizing should be followed with this parameter so that id's don't mess up) Appreciate any help<br />
<br />
Here is statement e.g. SQL statement that run in db2<br />
<br />
UPDATE gitem<br />
    SET gbaseprice=db1_local.gbaseprice <br />
FROM <br />
    db1_local.gitem(`gbaseprice`) <br />
    INNER JOIN db1_local.gitemtable <br />
    ON db1_local.gitem(`gitemcode`)=db2_local.gitem(`gitemcode`)]]></description>
            <dc:creator>Stuff Dole</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 26 Oct 2012 12:26:35 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,570834,570834#msg-570834</guid>
            <title>mysql query help (3 replies)</title>
            <link>http://forums.mysql.com/read.php?166,570834,570834#msg-570834</link>
            <description><![CDATA[ Hi all,<br />
       I am finding it difficult to build one mysql query.<br />
<br />
I have a table messages_stats_analysis_ota, with 4 columns: [brand_code, date_time_from, date_time_to, success_count].<br />
<br />
I want the value inside 'success_count' against individual 'brand_code', which lie within the last 7 days from the current date.<br />
<br />
u2, 01.10.2012, 07.10.2012, 100 <br />
u2, 02.10.2012, 08.10.2012, 100<br />
u2, 03.10.2012, 07.10.2012, 100<br />
u2, 08.10.2012, 14.10.2012, 50<br />
fr, 01.10.2012, 07.10.2012, 200<br />
<br />
<br />
Now lets assume, the current date is 08.10.2012.<br />
<br />
I want only the follwoing 2 rows to be retrieved:<br />
<br />
u2, 01.10.2012, 07.10.2012, 100 <br />
fr, 01.10.2012, 07.10.2012, 200<br />
<br />
I tried to build this query:<br />
<br />
SELECT * FROM messages_stats_analysis_ota WHERE date_time_from &gt;= DATE_SUB(CURDATE(), INTERVAL 7 DAY);<br />
<br />
but it gives me, the follwoing, which i dont want:<br />
<br />
u2, 01.10.2012, 07.10.2012, 100 <br />
u2, 02.10.2012, 08.10.2012, 100<br />
u2, 03.10.2012, 07.10.2012, 100<br />
fr, 01.10.2012, 07.10.2012, 200<br />
<br />
Assumtpion is current date is: 08.10.2012.<br />
<br />
Coudl someone please help me out?<br />
<br />
Thanks.]]></description>
            <dc:creator>Suleman Butt</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Fri, 02 Nov 2012 10:23:43 +0000</pubDate>
        </item>
        <item>
            <guid>http://forums.mysql.com/read.php?166,570730,570730#msg-570730</guid>
            <title>order by alphanumeric in mysql (1 reply)</title>
            <link>http://forums.mysql.com/read.php?166,570730,570730#msg-570730</link>
            <description><![CDATA[ Can you help me?<br />
<br />
my query is<br />
SELECT num FROM sortnum ORDER BY lpad(num, 10, 0)<br />
<br />
result of this query is not good<br />
here is the result<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
10<br />
11<br />
12<br />
13<br />
14<br />
A1<br />
A2<br />
A3<br />
A4<br />
B1<br />
A10<br />
A11<br />
B10<br />
<br />
What is the best query for this type of data<br />
i want number first, then data starting with a , then with b<br />
<br />
Thanks in advance]]></description>
            <dc:creator>vaibhav shahu</dc:creator>
            <category>MySQL Query Analyzer</category>
            <pubDate>Thu, 11 Oct 2012 13:59:29 +0000</pubDate>
        </item>
    </channel>
</rss>
