Jump to content

Query Help


ledtear

Recommended Posts

Given 3 tables:

 

Table 1

ID Name

1 Fred

2 Jim

3 Tom

 

 

Table 2

ID title

1 Apples

2 Bananas

3 Oranges

4 Grapes

 

 

Table 3

ID table1Id table2Id

1 1 2

2 1 4

3 3 2

4 3 1

 

Given a variable that has the value of Table 1.id - I want to return all of Table 2.title that Table 1.id does not have a record of on table 3 - so given Table 1.id = 1 I would get:

table 2.title = Apples, Grapes

 

make sense?

Link to comment
Share on other sites

 

So given Table 1.id = 1, I would get: table 2.title = Apples, Grapes

 

 

No, you wrong.

 

For userID 1, you should retrieve the titles - Apples and Oranges.

 

For userID 2 - All titles

 

For userID 3 - Oranges and Grapes

 

My solution is simple,

 

SELECT title FROM tabel2
WHERE id NOT IN (
SELECT table2Id
FROM tabel3
WHERE tabel1id = 1
)

Link to comment
Share on other sites

hmmm - thanks... that is not returning any results... I'll try to look into that more...

B/s your database is a case sensitive and Barand's used (t2.id = X.table2id), t2.id must be t2.ID.

 

My query is also wrong, it should be something like this

 

SELECT title FROM tabel2
WHERE ID NOT IN (
SELECT table2id
FROM tabel3
WHERE table1id = 1
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.