SQL Join Question

    Date: 04/18/07 (SQL Server)    Keywords: sql

    I have a multiple-table query that will involve either a left or right join, but am not sure how to approach this.

    table PERSON is primary table, with PK ID
    table SKILL is primary table, with PK SID
    table PERSON_SKILL is foreign m-to-m table, with FK PID = PERSON.PID and FK SID = SKILL.ID
    table PERSON_JOBS is foreign table, with FK PID = PERSON.ID, 1 to 1

    I would need to query all these at once. How accurate is this?

    SELECT p.* pj.job, ps.skill
    FROM PERSON p
    INNER JOIN PERSON_SKILL ps on ps.pid = p.id
    INNER JOIN SKILL s ON s.id = ps.sid
    INNER JOIN PERSON_JOBS pj ON j.pid = p.id


    In this case I've had multiple of the same records (in this case, from PERSON) returned because of the possibility of more than 1 record (or none, possibly) from PERSON_SKILL being returned. Is this where a left or right join comes into play?

    *Edited last line of SQL*

    Source: http://community.livejournal.com/sqlserver/57623.html

« Reporting Services || one quick question~ »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home