我有2个表收集并请求,当一个请求被创建它创建一个id,当该人获得总金额的一部分,它与贷款ID一起收集表,我需要回应请求信息以及基于loan_id收集的信息位于两个表上然后在PHP上获取此。
表请求
提交收集
select * from request, users where request.user_id = users.id and request.user_id = $user_id"这个select获取请求表
select * from collected where loan_id = 146 (loan_id from request table)我想要请求信息以及与请求表中的每个贷款ID相对应的收集的表信息
i have 2 tables collected and request, when a request is made it create an id, when the person get part of total amount it goes to collected tabled along with the loan id, i need to echo request info along with collected info based on loan_id that located on both tables then fetch this on php.
table request
tabled collected
select * from request, users where request.user_id = users.id and request.user_id = $user_id"this select gets the request table
select * from collected where loan_id = 146 (loan_id from request table)i will like to have request info along with collected table info corresponding to each loan id from request table
最满意答案
您可以使用Join(如果表列始终匹配,则使用内部联接)
select * from request inner join collected on request.loan_id = collected.loan_id inner join users on request.user_id = users.id Where request.user_id = $user_id如果列有时不匹配,则保持联接
select * from request left join collected on request.loan_id = collected.loan_id inner join users on request.user_id = users.id Where request.user_id = $user_idYou can use Join (inner join if the table column always match)
select * from request inner join collected on request.loan_id = collected.loan_id inner join users on request.user_id = users.id Where request.user_id = $user_idor left join if the column sometime don't match
select * from request left join collected on request.loan_id = collected.loan_id inner join users on request.user_id = users.id Where request.user_id = $user_id更多推荐
发布评论