itsme
itsme

Reputation: 575

Select two tables in one query PDO

I'v spent already a few hours to figure out this query but no result,

I'm actually new in PDO I used to do MYSQL but I saw here on stackoverflow that I have to change to PDO because MYSQL will be disabled soon,

So now to my question, I want to select two different tables with no relations one to other in one query like this,

$query = $dbh->query("SELECT * FROM table1; SELECT * FROM table2");
//rest of query,

How do I do that?

Upvotes: 2

Views: 5501

Answers (2)

dpitkevics
dpitkevics

Reputation: 1258

Or use JOIN

SELECT t1.id, t2.name FROM users AS t1 JOIN persons AS t2 ON t1.id = t2.id;

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359786

Just like how you'd do it with vanilla SQL:

$query = $dbh->query("SELECT * FROM table1, table2");

Upvotes: 4

Related Questions