473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

how to get this resultset...

Hi,

I have 3 tables as follow :

Kanji :
kanji_id
....

References :
ref_id
....

KanjiRefs
kref_idkanji
kref_idref
kref_value
....

So, there is a many-to-many relationship between Kanjis and References
(one kanji may have more than one reference type, and a reference type
may be set to more than one kanji).
For example, one kanji may have the value 'abc' for reference type #1,
and the value 'def' for reference type #2, another kanji may also have
the reference type #1, but have instead the value '123' and so on...

I have two questions :
1) How to get all kanjis that do NOT have the reference #3 (ref_id = 3)
within their list of references?

2) How to get the value of all the kanjis that have the reference #3,
but still get other kanjis that do not have the reference #3...for
example, if I had 3 kanjis, with the two first having values 'abc' and
'def' for reference #3, and the last one having no reference #3, I'd
like to get that resultset :
kanji_id kref_value
1 'abc'
2 'def'
3 NULL

I manage to get all the kanjis that have reference # 3 with the
following query :
SELECT kanji_id, kref_value
FROM Kanjis INNER JOIN kanjiRefs ON kref_idkanji = kanji_id
WHERE kref_idref = 3

however, this obviously does not include kanjis having no reference
#3...

any help would be greatly appreciated, thanks! :)
ibiza

Sep 24 '06 #1
2 1321
Try the following (untested):

SELECT kanji_id FROM Kanji
WHERE kanji_id NOT IN (
SELECT kref_idkanji FROM KanjiRefs
WHERE kref_idref=3
)

SELECT kanji_id, (
SELECT kref_value FROM KanjiRefs
WHERE kref_idref=3
AND kref_idkanji=kanji_id
) as kref_value
FROM Kanji

Razvan

Sep 24 '06 #2
wow! It all works :P

many thanks!

Razvan Socol wrote:
Try the following (untested):

SELECT kanji_id FROM Kanji
WHERE kanji_id NOT IN (
SELECT kref_idkanji FROM KanjiRefs
WHERE kref_idref=3
)

SELECT kanji_id, (
SELECT kref_value FROM KanjiRefs
WHERE kref_idref=3
AND kref_idkanji=kanji_id
) as kref_value
FROM Kanji

Razvan
Sep 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: RoyalScorpion | last post by:
hi guys, i get an updatable resultset from a connection then used it to insert a new row but the result set doesn't chane after insertion, i mean the no of rows before insertion is the same after...
1
by: Harrie K. | last post by:
I want to make an Stored Procedure on a Oracle 7.x database that fills a resulset based on the values in an array: CREATE OR REPLACE PACKAGE PCK_SET IS TYPE rec_set IS RECORD ( type_id NUMBER...
2
by: Savas Ates | last post by:
I have a stored procedure below.. When I run it with a well parameter in query analyser 3 of select statements return me. (i named select statements 1,2,3) But in asp page when i call this...
7
by: Gandalf | last post by:
Hi all, I am connecting to DB2 8.1 on Solaris through JDBC type 4 drivers (driver: com.ibm.db2.jcc.DB2Driver). Problem is that when a cursored query is done, the resultset gets closed after...
2
by: Twan Kennis | last post by:
Question: How do I pass a returning resultset from a nested Stored Procedure (which opens a cursor including option "WITH RETURN TO CALLER") as a returning resultset from it's own? When I...
4
by: _link98 | last post by:
Problem: java ResultSet cursor from SQL/PL stored-procedure is FORWARD_ONLY. Is it possible to have ResultSet cursors from SQL/PL procedures to scroll forward and backwards? Perhaps I am missing...
12
by: robertino | last post by:
Hi all, I've put together a few SPs to produce a BOM (bill of materials) listing, which together use a couple of global temp tables, and return the results from a cursor. Here's the code: ...
0
by: David Linsin | last post by:
I created a simple test case to reproduce the problem (also check Bug #15500): import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement;...
13
by: ajos | last post by:
hi frnds, im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class- for(resultset =...
5
by: lost1 | last post by:
I am having trouble adding a result set to a scroll pane. no matter what I do using getText I get an error. Can someon give me a clue? import java.util.*; import java.sql.*; import java.awt.*;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.