简体   繁体   English

使用Apache在Linux上的MySQL数据库中的三个表上进行内部,外部或完全联接

[英]Inner, outer or full join on three tables in MySQL database on linux with apache

I want to have some help creating my query to get information from three different tables sharing information in common. 我想在创建查询时获得一些帮助,以从共享相同信息的三个不同表中获取信息。 My first table is: 我的第一张桌子是:

auctions
id title description user_id(who posted it)

My second table is: 我的第二张桌子是:

bids
id user_id bid auction_id owner_id

My third table is: 我的第三张桌子是:

users
id username X XX XXX XXXX 

...and my SQL is as follows however it's not returning any results: ...而我的SQL如下,但是它不返回任何结果:

SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title FROM auction_bids, auctions
        WHERE auctions.user_id=".$_SESSION['userid']."  
        INNER JOIN users ON auction_bids.user_id = users.id 
        WHERE auction_bids.owner_id = ".$_SESSION['userid']."

What I need is to capture the auction's title, username who bidded on the auction and the bid. 我需要捕获拍卖的标题,在拍卖中出价的用户名和出价。 the auction has to have a bid and posted by the user who owns the $_SESSION['userid']. 拍卖必须有一个出价,并由拥有$ _SESSION ['userid']的用户发布。 Any help is appreciated. 任何帮助表示赞赏。

You have two different 'where' statements, which may just need combining; 您有两个不同的“ where”语句,可能只需要合并即可;

SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title FROM auction_bids, auctions INNER JOIN users ON auction_bids.user_id = users.id WHERE auction_bids.owner_id = ".$_SESSION['userid']." SELECT auction_bids.user_id AS申请人,auction_bids。*,auctions.title来自auction_bids,拍卖INNER JOIN用户ON auction_bids.user_id = users.id WHERE auction_bids.owner_id =“。$ _ SESSION ['userid']。” AND auctions.user_id=".$_SESSION['userid']." AND auctions.user_id =“。$ _ SESSION ['userid']。”

However, I'm not sure this is really what you want, as it will return only records where the specific user both 'owns' the item AND has bidded on it (both based on the userid session), rather than displaying all records from different people who have bidded on an item 'owned' by the user. 但是,我不确定这是否真的是您想要的,因为它只会返回特定用户既“拥有”该商品并对其进行了出价的记录(均基于userid会话),而不是显示来自该用户的所有记录对用户“拥有”的商品进行出价的不同人员。

Something like: ? 就像是: ? SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title FROM auction_bids, auctions INNER JOIN users ON auction_bids.user_id = users.id, WHERE auction.owner_id = ".$_SESSION['userid']." SELECT auction_bids.user_id作为AS申请人,auction_bids。*,auctions.title来自auction_bids,拍卖INNER JOIN用户,放在auction_bids.user_id = users.id,WHERE auction.owner_id =“。$ _ SESSION ['userid']”。

Hope this points you in the right direction! 希望这能为您指明正确的方向!

you have 2 where clauses, that is incorrect. 您有2个where子句,这是不正确的。 I have revised your query based on your requirements. 我已根据您的要求修改了您的查询。

SELECT auction_bids.user_id AS applicant, auction_bids.*, auctions.title 
FROM auction_bids, auctions
        INNER JOIN users ON auction_bids.owner_id = users.id 
        WHERE auction_bids.owner_id = ".$_SESSION['userid']."
        AND auctions.user_id=auctions_bids.owner_id  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM