Is it possible to use a SQL Join without specifying a second table in PHP?

When using a SQL Join in PHP, you typically need to specify at least two tables to join together. However, if you only want to retrieve data from a single table without joining it with another table, you can use a subquery in the Join statement to achieve this. By using a subquery that selects data from the same table, you can effectively use a Join without specifying a second table.

<?php
// Connect to database
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');

// Query to select data from a single table using a subquery in the Join statement
$sql = "SELECT t1.column1, t1.column2
        FROM table_name t1
        JOIN (SELECT column1, column2 FROM table_name) t2
        ON t1.column1 = t2.column1";

// Prepare and execute the query
$stmt = $pdo->prepare($sql);
$stmt->execute();

// Fetch the results
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Output the results
print_r($results);
?>