i have 4 tables like this
table0plus table10plus table20plus
[id - name ] [id - name ] [id - name - age]
[1 - garick] [1 - nizak] [1 - karin - 25 ]
[2 - garry ] [2 - nimar] [2 - kuster - 28 ]
tabletype
[ name - type ]
[ garry - male ]
[ nizak - female ]
[ karin - female ]
[ nimar - male ]
I'm trying to select all the values from all the tables, And what i've tried is
$query = "
SELECT a.id, a.name, b.type, '-20' AS age FROM table0plus a LEFT JOIN tabletype b ON a.name = b.name WHERE id = :id
UNION ALL
SELECT a.id, a.name, b.type, '-10' AS age FROM table10plus a LEFT JOIN tabletype b ON a.name = b.name WHERE id = :id
UNION ALL
SELECT a.id, a.name, b.type, a.age FROM table20plus a LEFT JOIN tabletype b ON a.name = b.name WHERE id = :id
ORDER BY age
LIMIT :limit
";
But it won't work and gives me an error.
I'm trying to output the values ordered by date or name or age
and all limited. How can i do that correctly?
the error is
Fatal error
: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number
and my PDO code is
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$stmt = $conn->prepare($query);
$stmt->execute(['id' => $id, 'limit' => $limit]);
tried to execute 'id' => $id
3 times but still the same problem.