Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Need help with array

Need help with array

2007-11-28       - By Armando Gomez

 Back
Reply:     1     2     3     4     5  

Hello all





I have a problem



I have 2 tables on MySQL  in the first one call patentes I just need to get
the patente's number that's a field call pat

So I do a  query like this one:





my $dbh = DBI->connect("DBI:mysql:database=proyecto;host=localhost",

                        "root", "xyz123",

                        {'RaiseError' => 1});

  my $sth = $dbh->prepare("SELECT DISTINCT PAT FROM patentes");



$sth->execute();
  while ((my @(protected)) = $sth->fetchrow_array()) {
  print "$row[0]\n";

So at this point I have all the patente's number on an array
Now, the other table call final I have all the data I need to work, what I
need is to get all the
Data from final but I need to extract the data by pat (both tables have the
same field) and at the same time
Create tables for each set of data that I get from using the the query
something like this :





my $dbh = DBI->connect("DBI:mysql:database=proyecto;host=localhost",

                        "root", "xyz123",

                        {'RaiseError' => 1});

  my $sth = $dbh->prepare("SELECT DISTINCT PAT FROM patentes");



$sth->execute();
  while ((my @(protected)) = $sth->fetchrow_array()) {
  print "$row[0]\n";



my $a_dbh = DBI->connect("DBI:mysql:database=proyecto;host=localhost",

                        "root", "xyz123",

                        {'RaiseError' => 1});

  my $a_sth = $a_dbh->prepare("SELECT * INTO $row[0] FROM final

                                        WHERE pat = $row[0]");



}


But every time I try it gives my an error message

Can anyone help me to fix the problem thank you



This is an example of what I need

Table :  patente               Table : Final

Pat    Name                    pat     dept      course
0001   John                    0001    SCIFI     MATH ADVANCE
0002   Jack                    0001    SCIFI     Quark study
0003   Peter                   0001    SCIFI     TIME STUDY
                              0002    WAR       STRATEGIC PHILO.
                              0002    WAR       COUNTERMEASURES
                              0003    POLITICS  DIPLOMATIC RELATIONS
                              0003    POLITICS  ADDRESS STUDY

So for pat 0001:

I need to create a table contains this:

Table : 0001

0001    SCIFI     MATH ADVANCE
0001    SCIFI     Quark study
0001    SCIFI     TIME STUDY


Table : 0002

0002    WAR       STRATEGIC PHILO.
0002    WAR       COUNTERMEASURES


Table : 0003

0003    POLITICS  DIPLOMATIC RELATIONS
0003    POLITICS  ADDRESS STUDY



So at the end I have all these tables in the database

Patente
Final
0001
0002
0003


Thanks