drxpt06820 2018-03-17 14:58
浏览 93
已采纳

INNER JOIN在mysql php中

I have a little problem with INNER JOIN in mysql query. I have two tables the first is 'kontrola' and 2nd is 'naruszenia' In 'kontrola' table I have rows:

  • id
  • podmiot
  • miasto
  • wszczeto
  • zakonczono
  • naruszenie_id (Foreign KEY on 'naruszenia' table) In my naruszenia table I have:

  • id

  • naruszenia

Now I want to display using INNER JOIN the naruszenie from 'naruszenia' table. I've create somethin linke this:

$listakontroli = $connecting->query("SELECT * FROM kontrola INNER JOIN naruszenia ON
 kontrola.naruszenie_id=naruszenia.id"); 

But the result is that when I want to display records in table I have changed the ID of first table(kontrola) and the naruszenia_id still showing id from naruszenia table. How to change it to display properly the word not id.

  • 写回答

2条回答 默认 最新

  • dps57553 2018-03-17 15:03
    关注

    You could use explicit column name and refer to both the table (in this case using k an n) eg:

    $listakontroli = $connecting->query("SELECT k.id
               , k.podmiot
               , k.miasto
               , k.wszczeto7
               , k.zakonczono
               , n.naruszenia 
          FROM kontrola k
          INNER JOIN naruszenia  n ON  k.naruszenie_id=n.id"); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决