Note that there are some explanatory texts on larger screens.

plurals
  1. POmySQL how to merge statements
    primarykey
    data
    text
    <ol> <li>I have two statements</li> </ol> <p>a. </p> <pre><code>while (($row_1 = $STH_1 -&gt; fetch_assoc()) !== null){ $table_name = $row_1['table_name']; $stmts_1[] = sprintf(" SELECT * FROM $table_name WHERE date_time = $today_date "); } $stmt_1 = implode("\nUNION\n", $stmts_1); $stmt_1 .= "\nORDER BY date_time ASC"; $STH_5_2 = $DBH_R-&gt;query($stmt_1); while (($row_5_2 = $STH_5_2 -&gt; fetch_assoc()) !== null) { } </code></pre> <p>b. </p> <pre><code>$STH_e = $DBH_R-&gt;query(" SELECT * FROM $table_name_2 WHERE date_time = $today_date "); while (($row_e = $STH_e -&gt; fetch_assoc()) !== null) { } </code></pre> <ol> <li>the source colums for query 1 and query 2 are differents</li> <li>one column are similar -> date_time, but TIME(date_time) are different, DATE(date_time) will be the same</li> <li>all I must merge into one list (ORDER BY TIME(date_time) ASC) to make source for ticker script</li> </ol> <p>Q: how to merge this two statements? or maybe this two queries?</p> <p>//------------------------------------------------------------- update - create table statement</p> <ol> <li><p>table for query 1 - this type near 30 tables</p> <p>CREATE TABLE IF NOT EXISTS <code>v_c_ei_9001</code> (</p> <p><code>id</code> int(11) unsigned NOT NULL AUTO_INCREMENT,</p> <p><code>ei_code</code> int(10) NOT NULL DEFAULT '0',</p> <p><code>date_time</code> datetime NOT NULL DEFAULT '0000-00-00 00:00:00',</p> <p><code>index_year</code> varchar(10) NOT NULL DEFAULT 'ndnc',</p> <p><code>index_period</code> varchar(10) NOT NULL DEFAULT 'nd',</p> <p><code>index_period_2</code> varchar(10) NOT NULL DEFAULT 'nd',</p> <p><code>index_unit</code> varchar(10) NOT NULL DEFAULT 'nd',</p> <p><code>index_comment</code> text NOT NULL,</p> <p>PRIMARY KEY (<code>id</code>), KEY <code>date_time</code> (<code>date_time</code>) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=608 ;</p></li> <li><p>table for query 2 - this type is only one</p> <p>CREATE TABLE IF NOT EXISTS <code>v_c_e</code> (</p> <p><code>id</code> int(11) unsigned NOT NULL AUTO_INCREMENT,</p> <p><code>country_code</code> int(10) NOT NULL DEFAULT '0',</p> <p><code>country_name</code> varchar(50) NOT NULL DEFAULT 'ndnc',</p> <p><code>date_time</code> datetime NOT NULL DEFAULT '0000-00-00 00:00:00',</p> <p><code>event_title</code> varchar(100) NOT NULL DEFAULT 'ndnc',</p> <p><code>event_released</code> int(10) NOT NULL DEFAULT '0',</p> <p><code>event_comment</code> varchar(500) NOT NULL DEFAULT 'ndnc',</p> <p>PRIMARY KEY (<code>id</code>) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=168 ;</p></li> </ol> <p>brgs</p> <p>//--------------------------------------------------- UPDATE 2</p> <p>pre-query code // from all tables in the dbase we query only tables with names like v_c_ei_9xxx</p> <pre><code>$STH_1 = $DBH_R-&gt;query("SELECT table_name FROM information_schema.tables WHERE table_name LIKE 'v_c_ei\_9%' "); $stmts_1 = array(); while (($row_1 = $STH_1 -&gt; ..... // as above </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload