Matpatnik Posted December 11, 2007 Share Posted December 11, 2007 Hi guys,is it possible to select a range of table?something that will select all table starting with the first letter a or b...I'm using MySQL db Link to comment Share on other sites More sharing options...
justsomeguy Posted December 11, 2007 Share Posted December 11, 2007 You can use BETWEEN to get a range.http://dev.mysql.com/doc/refman/4.1/en/com...perator_betweenIf you want to get string fields that contain another string you can use LIKE with the wildcard.get rows starting with 'a':SELECT * FROM table WHERE col LIKE 'a%'get rows ending with 't':SELECT * FROM table WHERE col LIKE '%t'get rows containing 'cat':SELECT * FROM table WHERE col LIKE '%cat%' Link to comment Share on other sites More sharing options...
Matpatnik Posted December 11, 2007 Author Share Posted December 11, 2007 I was looking more for table instead of the row and columnsomething in this logic: (I know, it doesn't work )SELECT *FROM 'a*' Link to comment Share on other sites More sharing options...
Synook Posted December 11, 2007 Share Posted December 11, 2007 Umm... but how would the engine merge the tables together? You could use JOIN with rules. Link to comment Share on other sites More sharing options...
Matpatnik Posted December 11, 2007 Author Share Posted December 11, 2007 We will have (in a close future) so many information stored in our db so I decide to set it like thathere is my db, we have 936 tbls so 36 tbls of each letter $start = 97;for ($f=0; $f<26; $f++) { for ($s=0; $s<123; $s++) { // ignore character 0-47 and 58-96 // so just keep 0-9 and a-z (no capital letters) if (($s >= 0 && $s < 48) || ($s > 57 && $s < 97)) { // skip the rest and continue the for loop continue; } // add a second character $lettre = chr($start+$f) . chr($s); // escape illegal name by doubling the second letter switch ($lettre) { case 'as': $lettre = '######'; break; case 'by': $lettre = 'byy'; break; case 'if': $lettre = 'iff'; break; case 'in': $lettre = 'inn'; break; case 'is': $lettre = 'iss'; break; case 'on': $lettre = 'onn'; break; case 'or': $lettre = 'orr'; break; case 'to': $lettre = 'too'; break; } $sql = "CREATE TABLE ". $lettre ." (id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ...);"; $results = mysql_query($sql) or die (mysql_error() .' => '. $lettre); } echo 'All table '. chr($start+$f) .' successfully created!<br>';} our problem right now is we are trying to make a button (with VB) that will select all the tables of that specific first letter in the dbwe was thinking of SELECT * FROM a1,a2,a3,a4,a5,a6,a7,a8... but the thing is that it put all the information in 1 row and rename the column like thisid | id_1 | id_2 | id_3 | id_4 | ... we are not sure but we think that can become a problem later Link to comment Share on other sites More sharing options...
justsomeguy Posted December 11, 2007 Share Posted December 11, 2007 It sounds like a problem to have 36 tables for each letter of the alphabet. There's no way to use wildcards in table selection, only row selection. The list of table names to select from cannot be an expression, only a list of tables with JOIN syntax.http://dev.mysql.com/doc/refman/4.1/en/select.htmlIt might be better to redesign the database. Link to comment Share on other sites More sharing options...
Synook Posted December 11, 2007 Share Posted December 11, 2007 If all the tables are identical then you could just have one table with extra columns that differentiate between letters, then each time you INSERT you just set the values of that column to the required letter sequence.Fewer tables are always better. Link to comment Share on other sites More sharing options...
Guest sus4827 Posted December 14, 2007 Share Posted December 14, 2007 Hi,You can get a list of tables with name like 'pattern' . Not sure if this will help you. Just check it out.The query is:select * from sysobjects where name like 'a%';This will list out all the tables starting with letter 'a'. You can use BETWEEN to get a range.http://dev.mysql.com/doc/refman/4.1/en/com...perator_betweenIf you want to get string fields that contain another string you can use LIKE with the wildcard.get rows starting with 'a':SELECT * FROM table WHERE col LIKE 'a%'get rows ending with 't':SELECT * FROM table WHERE col LIKE '%t'get rows containing 'cat':SELECT * FROM table WHERE col LIKE '%cat%' Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.