dongyuan4790 2019-04-11 20:07
浏览 57

当使用同一数据库中的两个不同的表格时,如何将两个不同的sql查询组合成一个变量?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)