I have the following two queries which I would like to be written in one variable only to safe space and in general, to be more efficient when writing queries.
I have seen many other answers suggesting using UNION
but I don't think my two queries are UNION
compatible.
This is the interesting part of the file and then I'm just updating sql1
and sql2
and ending the connection with the database in the rest of the file so I will just share the queries.
<?php
require("somePathName/someFileName.php");
$id = (isset($_GET["id"])?intval($_GET["id"]):"");
if (!$id) exit();
$sql1 = "SELECT A, B, C, D, E, F FROM `".$config_databaseTablePrefix."products` WHERE id='".database_safe($id)."'";
$sql2 = "SELECT G FROM `".$config_databaseTablePrefix."people` WHERE id='".database_safe($id)."'";
I'm wondering if there's a way to save myself some work and make only one variable of sql1
and sql2
that is called sql
that does exactly what these two variables do.
EDIT: These two tabels share the primary key but notice that none of the selected items are the same. Not sure how helpful this is.