Re: Doing multiple joins on one table



On Sat, 2 Sep 2006 22:26:02 +0200, Yaniv Danan wrote:

I have those Tables:

CREATE TABLE GameYellows(

id INT NOT NULL AUTO_INCREMENT,
(snip)

Hi Yaniv,

AUTO_INCREMENT is not a recognised keyword in SQL Server. If you're
using a different DBMS, you might try finding a group for that DBMS in
order to get better replies. All DBMS's have their specific quirks, so
what works goood in one might perform awfully or not work at all in
another.

As to your problem:

What i need is actually to get a table of statistics for each player in the
players table.
(snip)
please help me solve this one, having hard time using join.

Try it like this:

SELECT p.id, y.id AS yellows, r.id AS reds,
so.id AS subsititutes_out, si.id AS subsititutes_in
FROM Players AS p
LEFT OUTER JOIN GameYellow AS y ON y.Player_ID = p.id
LEFT OUTER JOIN GameReds AS r ON r.Player_ID = p.id
LEFT OUTER JOIN GameSubsititues AS so ON so.OutPlayer_ID = p.id
LEFT OUTER JOIN GameSubsititues AS si ON si.OutPlayer_ID = p.id
ORDER BY p.id;

--
Hugo Kornelis, SQL Server MVP
.



Relevant Pages

  • Re: LEFT OUTER JOIN possible in DB2?
    ... i was trying to get a customer to create a view on their IBM thingy. ... Now, OS/400 comes with its own DBMS, which I assume is at a lower level that an RDBMS, like DB2 or SQL Server. ... > Turns out a LEFT OUTER join is sorta possible in IBM/DB2/AS/400. ...
    (microsoft.public.sqlserver.programming)
  • Re: Flattening Parent Child, an issue, please help
    ... AND t2.WBS_LEVEL = 2 LEFT OUTER JOIN ... I am using SQL Server 2000 with SP4. ... For information about dyamic SQL from T-SQL see ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: Flattening Parent Child, an issue, please help
    ... in future when all divisions would start using Project Module. ... AND t2.WBS_LEVEL = 2 LEFT OUTER JOIN ... I am using SQL Server 2000 with SP4. ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: How to query with both JOIN and aliases in Access?
    ... v.empID LEFT OUTER JOIN FirstDayWorked FROM ... This query performs in SQL Server without any problem. ... LEFT OUTER JOIN (SELECT empID, ...
    (microsoft.public.access.queries)
  • Re: Updating linked tables
    ... An outer join is the way to go... ... I support the Professional Association of SQL Server and it's community of SQL Server professionals. ... > I have a users table that stores basic information for all users. ... > FirstName VARCHAR NOT NULL, ...
    (microsoft.public.sqlserver.server)