Jump to content

Left join from two columns


skyhighweb

Recommended Posts

i need to connect team1 and team2 to a table called sports so i can get there names which is in column called (teams) how do i do that i already connected sports to another table as u can see in the code, how do i go about this, thanks.

$query = "SELECT s.team_id, s.teams, a.current_bid, a.current_bid_id, a.id, a.team1, a.title, a.team2, a.ends, a.starts, u.nick, b.bid, b.tagged, b.bidder, b.willwin, b.quantity, p.bid As proxybid, b.id As bid_id FROM " . $DBPrefix . "bids b
LEFT JOIN " . $DBPrefix . "proxybid p ON (p.itemid = b.auction AND p.userid = b.bidder)
LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
LEFT JOIN " . $DBPrefix . "auctions a ON (a.id = b.auction)
LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.tagged)

 

Link to comment
Share on other sites

ok done did it this way just incase someone wants to know how

$query = "SELECT sss.team_id, sss.teams AS teams2, ss.team_id, ss.teams AS teams1, s.team_id, s.teams, a.current_bid, a.current_bid_id, a.id, a.team1, a.title, a.team2, a.ends, a.starts, u.nick, b.bid, b.tagged, b.bidder, b.willwin, b.quantity, p.bid As proxybid, b.id As bid_id FROM " . $DBPrefix . "bids b
	LEFT JOIN " . $DBPrefix . "proxybid p ON (p.itemid = b.auction AND p.userid = b.bidder)
	LEFT JOIN " . $DBPrefix . "sports s ON (s.team_id = b.willwin)
	LEFT JOIN " . $DBPrefix . "auctions a ON (a.id = b.auction)
	LEFT JOIN " . $DBPrefix . "sports ss ON (ss.team_id = a.team1)
	LEFT JOIN " . $DBPrefix . "sports sss ON (sss.team_id = a.team2)
	LEFT JOIN " . $DBPrefix . "users u ON (u.id = b.tagged)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...