I’m having two tables like A and B. Table A having the Columns Name. Table B having the Columns Company Name.
This is my code:
$query1 = "SELECT Name FROM A";
$query2 = "SELECT Company Name FROM B";
$statement1 = $connection->prepare($query1);
$statement2 = $connection->prepare($query2);
$statement1->execute();
$statement2>execute();
while ( ($name) = $statement->fetchrow_array) {
push (@Name, $name);
}
while ( ($companyname) = $statement->fetchrow_array) {
push (@companyName, $companyname);
}
open (FH, ">>Output.csv") or die "$!";
I need to write the data in the csv file like this
Name CompanyName
xxx yyyy
xxx yyyy
xxx yyyy
xxx yyyy
xxx yyyy
You can do that with a
JOINin your SQL query. You don’t need to do twoSELECTstatements.Here’s a complete example: