| | |
Confused?
Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved |
Hello all,
hope i can get some help on this one as im not brilliant with my database scripts.
I have table "A" and table "B", table "A" contains information on a portfolio and table "B" is a joining table which connects this table to a user of the system with a 1-to-many relationship.
I am looking to return all records in table "A" that are not connected to a user in table "B"
i have tried this
but i know this is incorrect but cannot figure out myself how to achieve what i want.
Hopefully someone can point me in the right direction.
hope i can get some help on this one as im not brilliant with my database scripts.
I have table "A" and table "B", table "A" contains information on a portfolio and table "B" is a joining table which connects this table to a user of the system with a 1-to-many relationship.
I am looking to return all records in table "A" that are not connected to a user in table "B"
i have tried this
MS SQL Syntax (Toggle Plain Text)
SELECT a.* FROM a LEFT JOIN b ON a.id = b.id WHERE b.userid <> 1
but i know this is incorrect but cannot figure out myself how to achieve what i want.
Hopefully someone can point me in the right direction.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM Table1 a LEFT JOIN Table2 b ON (a.id = b.id) WHERE a.id <> '1'
Last edited by Jx_Man; Mar 21st, 2008 at 4:05 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
•
•
MS SQL Syntax (Toggle Plain Text)
SELECT * FROM Table1 a LEFT JOIN Table2 b ON (a.id = b.id) WHERE a.id <> '1'
It simply filters table A's records removing the one with an id of '1'.
its probably easier with a working example.
I have the following tables...
### 'portfolio' - table
'portfolioid' - int [primary key]
'usertitle' - string
'clienttitle' - string
### Records
1, "test title", "test title"
2, "test title 1", "test title a"
3, "test title 2", "test title b"
4, "test title 3", "test title c"
### 'portfolioclient' - table
'portfolioid' - int
'clientid' - int
### Records
1, 1
3, 1
2, 2
4, 2
i wish to return all portfolio records which are not attached to a 'clientid'. E.G. if a client has an ID of '1' then the portfolio records returned should be 2 and 4.
i thought this would work but obviosuly not.
MS SQL Syntax (Toggle Plain Text)
SELECT portfolio.* FROM portfolio LEFT JOIN portfolioclient ON portfolio.portfolioid = portfolioclient.portfolioid WHERE portfolioclient.clientid <> 1
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Ok managed to solve this one myself after a bit of staring at my screen for a long time. For anyone interested this worked for me...
MS SQL Syntax (Toggle Plain Text)
SELECT portfolio.portfolioid FROM portfolio WHERE (NOT EXISTS (SELECT portfolioclient.* FROM portfolioclient WHERE (portfolio.portfolioid = portfolioclient.portfolioid) AND (portfolioclient.clientid = 1)))
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
![]() |
Similar Threads
- confused about SE + SEO. (Search Engine Optimization)
- Confused about SATA RAID (Storage)
- Confused about loops and switch (Java)
- Confused writing a Java Class (Java)
- confused about shell sort ... (C)
- confused how to begin this program (C++)
- Need help With this C++ Program..Confused.. (C++)
- ftp client issues...im so confused...plz help!!! (Windows Software)
Other Threads in the MS SQL Forum
- Previous Thread: SQL 2000 ODBC and SP4 problem
- Next Thread: Database Capability - # of Transactions
| Thread Tools | Search this Thread |






