doutou19761022 2014-04-24 10:02
浏览 25

MYSQL PHP通过一个查询跳过许多表

Is it possible to get data from one table when necessary data is in the other one(and so on a few times)? I mean, I have to get result, fetch array, pull all the data in php, make another query... and repeat it a several times before I get the wanted result. Could it be done in one query or have you guys got any ideas about optimization for such issue? I've been searching, but I really didn't find anything what makes sense for me.

UPDATE: Thanks! JOIN fixed my problems but I got some more to work on. Let's say I've got tables like this Users:

ID  Name
1   Adam
2   John
3   Lana



Roles(with users ids)
ID  Name         Cleaner   Soldier   Doctor 
1   Ship crew    2         1         3

How can I get my result like: [1,Ship crew,John,Adam,Lana] in php without making many queries? I mean I'd like to load records from another table for a several fields depending on primary key ID.

EDIT: OK I got it, I just needed some practice with mysql. It's not so hard as I thought it could be. Thanks for that join now I know what I was looking for :)

  • 写回答

1条回答 默认 最新

  • doue1925 2014-04-24 10:22
    关注

    It is possible yes, you can use the "JOIN" technique to collate the tables or you can use the "IN" clause in your query .

    http://www.tutorialspoint.com/mysql/mysql-in-clause.htm

    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)