How can I use EXISTS and no SEPARATE in this query? DDL/DML (attached)
Example queries SQL start - from the beginner to the professional by Clare Churcher(sorry about the long example script)I have 3 tables: Member, entry, tournament (scripts DDL/DML attached below).
The members and tournament tables have no common column. Member.Membertype and Tournament.tourtype are different columns despite the similarity of its content
Table 1. Member
MEMBERID LASTNAME FIRSTNAME MEMBERTYPE
--------- -------------------- -------------------- --------------
118 McKenzie Melissa Junior
138 Stone Michael Senior
153 Nolan Brenda Senior
176 Branch Helen Social
178 Beck Sarah Social
228 Burton Sandra Junior
235 Cooper William Senior
239 Spence Thomas Senior
258 Olson Barbara Senior
286 Pollard Robert Junior
290 Sexton Thomas Senior
323 Wilcox Daniel Senior
331 Schmidt Thomas Senior
332 Bridges Deborah Senior
339 Young Betty Senior
414 Gilmore Jane Junior
415 Taylor William Senior
461 Reed Robert Senior
469 Willis Carolyn Junior
487 Kent Susan Social
20 rows selected.
Table 2: Entry
MEMBERID TOURID YEAR
---------- ---------- ----------
118 24 2005
228 24 2006
228 25 2006
228 36 2006
235 38 2004
235 38 2006
235 40 2005
235 40 2006
239 25 2006
239 40 2004
258 24 2005
258 38 2005
286 24 2004
286 24 2005
286 24 2006
415 24 2006
415 25 2004
415 36 2005
415 36 2006
415 38 2004
415 38 2006
415 40 2004
415 40 2005
415 40 2006
24 rows selected.
Table 3: Tournament
TOURID TOURNAME TOURTYPE
-------- -------------------- --------------
24 Leeston Social
25 Kaiapoi Social
36 WestCoast Open
38 Canterbury Open
40 Otago Open
My requirement:+.I need to find the names of all those who entered the tournament Open (tournament. Tourtype = open). So I wrote the following query
select distinct m.memberid, m.lastname, m.firstname, t.tourtype
from
member m inner join entry e on (m.memberid=e.memberid)
inner join tournament t on (e.tourid=t.tourid)
and upper(t.tourtype)='OPEN'
order by m.lastname;
It gives me a correct result. MEMBERID LASTNAME FIRSTNAME TOURTYPE
-------- ---------- ---------- ------------------
228 Burton Sandra Open
235 Cooper William Open
258 Olson Barbara Open
239 Spence Thomas Open
415 Taylor William Open
But it means I can write this SQL using operator EXISTS?The DDL and DML to tables and their data
CREATE TABLE Type(
Type VARCHAR2(20) Primary Key,
Fee number)
/
CREATE TABLE Member(
MemberID NUMBER Primary Key,
LastName VARCHAR2(20),
FirstName VARCHAR2(20),
MemberType VARCHAR2(20) constraint fk1_member References type(type),
Phone VARCHAR2(20), Handicap NUMBER, JoinDate DATE, Coach NUMBER, Team
VARCHAR2(20), Gender VARCHAR2(1))
/
CREATE TABLE Tournament(
TourID NUMBER Primary Key,
TourName VARCHAR2(20),
TourType VARCHAR2(20))
/
CREATE TABLE Entry(
MemberID NUMBER constraint fk1_entry References Member(memberid),
TourID NUMBER constraint fk2_entry References Tournament(tourid), Year
NUMBER,
constraint pk_entry Primary Key (MemberID, TourID, Year))
/
Insert into Type values ('Junior',150)
/
Insert into Type values ('Senior',300)
/
Insert into Type values ('Social',50)
/
Insert into Member values
(118,'McKenzie','Melissa','Junior','963270',30,null,null,null,'F')
/
Insert
into Member values
(138,'Stone','Michael','Senior','983223',30,null,null,null,'M')
/
Insert
into Member values
(153,'Nolan','Brenda','Senior','442649',11,null,null,'TeamB','F')
/
Insert
into Member values
(176,'Branch','Helen','Social','589419',null,null,null,null,'F')
/
Insert
into Member values
(178,'Beck','Sarah','Social','226596',null,null,null,null,'F')
/
Insert
into Member values
(228,'Burton','Sandra','Junior','244493',26,null,null,null,'F')
/
Insert
into Member values
(235,'Cooper','William','Senior','722954',14,null,null,'TeamB','M')
/
Insert into Member values
(239,'Spence','Thomas','Senior','697720',10,null,null,null,'M')
/
Insert
into Member values
(258,'Olson','Barbara','Senior','370186',16,null,null,null,'F')
/
Insert
into Member values
(286,'Pollard','Robert','Junior','617681',19,null,null,'TeamB','M')
/
Insert into Member values (290,'Sexton
','Thomas','Senior','268936',26,null,null,null,'M')
/
Insert into Member
values (323,'Wilcox','Daniel','Senior','665393',3,null,null,'TeamA','M')
/
Insert into Member values
(331,'Schmidt','Thomas','Senior','867492',25,null,null,null,'M')
/
Insert
into Member values
(332,'Bridges','Deborah','Senior','279087',12,null,null,null,'F')
/
Insert
into Member values
(339,'Young','Betty','Senior','507813',21,null,null,'TeamB','F')
/
Insert
into Member values
(414,'Gilmore','Jane','Junior','459558',5,null,null,'TeamA','F')
/
Insert
into Member values
(415,'Taylor','William','Senior','137353',7,null,null,'TeamA','M')
/
Insert
into Member values
(461,'Reed','Robert','Senior','994664',3,null,null,'TeamA','M')
/
Insert
into Member values
(469,'Willis','Carolyn','Junior','688378',29,null,null,null,'F')
/
Insert
into Member values
(487,'Kent','Susan','Social','707217',null,null,null,null,'F')
/
Insert into Tournament values (24,'Leeston','Social')
/
Insert into Tournament values (25,'Kaiapoi','Social')
/
Insert into Tournament values (36,'WestCoast','Open')
/
Insert into Tournament values (38,'Canterbury','Open')
/
Insert into Tournament values (40,'Otago','Open')
/
Insert into Entry values (118,24,2005)
/
Insert into Entry values (228,24,2006)
/
Insert into Entry values (228,25,2006)
/
Insert into Entry values (228,36,2006)
/
Insert into Entry values (235,38,2004)
/
Insert into Entry values (235,38,2006)
/
Insert into Entry values (235,40,2005)
/
Insert into Entry values (235,40,2006)
/
Insert into Entry values (239,25,2006)
/
Insert into Entry values (239,40,2004)
/
Insert into Entry values (258,24,2005)
/
Insert into Entry values (258,38,2005)
/
Insert into Entry values (286,24,2004)
/
Insert into Entry values (286,24,2005)
/
Insert into Entry values (286,24,2006)
/
Insert into Entry values (415,24,2006)
/
Insert into Entry values (415,25,2004)
/
Insert into Entry values (415,36,2005)
/
Insert into Entry values (415,36,2006)
/
Insert into Entry values (415,38,2004)
/
Insert into Entry values (415,38,2006)
/
Insert into Entry values (415,40,2004)
/
Insert into Entry values (415,40,2005)
/
Insert into Entry values (415,40,2006)
/
Hello, because you select tournament.tourtype in the SELECTION list, the answer is not really. If you have need of t.tourtype in the SELECT list, you might have:
select m.memberid, m.lastname, m.firstname
from member m
where exists (select 1
from entry e inner join tournament t on (e.tourid=t.tourid)
where m.memberid=e.memberid
and upper(t.tourtype)='OPEN');
And you know that the t.tourtype is 'OPEN' anyway, if you do not need to SELECT. So, you may have it, and the answer is Yes:
select m.memberid, m.lastname, m.firstname, 'OPEN' tourtype
from member m
where exists (select 1
from entry e inner join tournament t on (e.tourid=t.tourid)
where m.memberid=e.memberid
and upper(t.tourtype)='OPEN');
Published by: Seanmacgc on May 7, 2009 02:09
Tags: Database
Similar Questions
-
How can I use / instead of - to separate my website'pages?
I am doing a url like this: https://www.Adobe.com/br/products/Muse.html ,
using the / to separate my website'pages.
When I try to do, software changes to.
Hello
You must change the folder structure to get this configuration, Muse currently does not allow this. I add a few threads, which may be useful for this
Change the structure of folders in Adobe Muse?
How can I structure my muse with records cc site
If you can't find something useful, please add your vote here
Add the folder Structure for Adobe Muse
Let me know if you have any question.
-
How can I use 'fscanf' and 'fread' (matlab code) in Labview
Hello, all,.
I'm trying to write a VI according to my matlab file, now I m confused about 'fscanf' and 'fread ',.
I used the VISA-reading slot - VI for the function 'fread' but who don't know for the "fscanf.
and I don't know how to read the datamatrix with a Subvi.
Is there someone can give me a tip, which will be very nice, thank you.
your
Adam
Hello, everyone,
I think that I found how to solve my problem. (The interface control series)
fscanf expressing indeed as VISA-read in Labview and very time you use fscanf, wants to write something in the device memory,
for example:
fprintf = VISA / writing
fscanf = VISA-read, but the value that was read is stored in the memory of the device, when you perform an indicator for the release of the VISA-read, this value will be shown and remove from the device memory. It's for my device OTDR, I don't know if everything is going well for any other device of m.
When you want to read the datamatrix, for example in 2D, just use VISA read twice.
When you still have any questions about this, feel free to ake, I'll try to answer you.
Your
Adam Yuan
-
How can I use search and replace to replace the title of the doc with copy of the h1 content?
I have a site with about 300 pages which have the same title. I need to replace this title by the same text that appears in the h1 tag on the page (each page is different). Of DW search and replace it? If so, how? I don't really want to go have to go to each page and copy/paste.
jeffsure wrote:
Is there a way to tell him to put only the first h1 tag in the title?
I'm really motivated now to learn regex!
Yes. Just use the following regular expression instead of the previous:
([^<> [\S\s]+?)([^<>
The field is to replace the same.
The question mark is the [\S\s]+ a lazy search, stopping at the first]
rather than doing a greedy research that concludes the last
in the page.
The regex for learning is difficult, but it can be very rewarding. I would only like the best.
-
Query - How can I use POP3 and Port 110 as my transport?
My e-mail provider can use POP3 (port 110) or IMAP (port 143) that the port of mail transport.
E-mail on my TP does not seem to work with port 143. Is it possible to make it work with port 110?
Alan
Of course, you can manually enter the server name and the port number for any account.
- Open Email.
- Open the application menu at the top left, tap Preferences & accounts, tap the account you want to change.
- Scroll down to change the connection settings and then on the installation manual.
- Enter the information for the incoming and outgoing as expected POP or IMAP mail server.
If you must change the type of email from IMAP POP you need to delete the account and re-create it again, and choose to enter the settings manually.
-
How can I use Adobe and a camera at the same time?
I am a musician and I put to read sheet music and record with the camera to the IPad. But whenever I left the window of the camera and switch to Adobe agani, the camera stop recording.
I can't save IM reading the notes of music at Adobe.
I use Air from the IPad.
Nobody helps me?
Thank you.
Hi Edusax,
It seems to be the limitation of the device because it doesn't have the split screen function to use two applications at the same time.
You will need two devices else you can print the PDF to read sheet music.
Kind regards
Nicos
-
How can I use Nav and duly points together?
Hi team,
I want to use the functionality of these two points of NAv and landmarks at the same time! I'm cooking these points using first pro and I can't have 2 different points (nav and cue) at the same place. What about Actionscript cue points, what can they be used?
Hich tips, I want to have a seek for this nav point and then do something when you reach the next point (which is also a point of nav)
Is it just a matter of getting a framework of nav and cue point 1 apart?
See you soon
void
You can use cuepoints (timed) to call an actionscript function when they occur. You can use (named) cuepoints for navigation within your video.
-
How can I use my time capsule as a hard drive on an existing network accessed through a password
How can I use my time capsule as a hard drive on an existing network, storage, accessed through a password?
We need more information in order to provide the right solution and Setup for you.
You already have another router Apple... as an AirPort Extreme or Airport Express that provides the signal of your wireless network?
If not, what is the serial number and model of your modem?
Finally, what operating system is installed on the device you will use to install and configure the time Capsule? If it's a Mac and you're not sure what operating system it uses... click on the Apple icon in the upper left corner of the screen, then click on about this Mac, and post back with number of Version of OS X that you see there.
-
Hello
I use thunderbird for 3 e-mail accounts (POP, no message left on the server server), and I need returned my OS (win7).
How can I back up and reinstall account 3 without losing records "Inbox" and "sent"?Is it enough to copy the folders in Thunderbird/Profiles/Default/Mail, reinstall the OS and Thunderbird, create 3 email accounts in Thunderbird and replace the files newly created in the path above with old mail folders?
Thank you very much
lSo basically I have reinstall 1 backup the entire contents of the folder Thunderbird lies in AppData/Roaming 2 OS and Thunderbird 3 Replace folder Thunderbird above with the old
Yes, that's all!
Blockquotes <>what accounts? < / blockquote >
The profile that you have is all you need. It is ' just ' copy him on the same place in your new configuration.Oh and make sure Thunderbird is closed when you perform your copy.
-
I bought an iphone 4 on ebay but it's locked, icloud so I am not able to use it, and the previous owner is available to remove the device from their account: How can I use the appliance?
You can not. Try to return the unit and get your money back. There is absolutely no way for you to unlock the device,
-
What is SSD and how can I use it or not?
Could someone tell me, what is SSD and how can I use it or not? because my friend told me that my laptop has SSD drive.
Hi Jabbar73,
Thanks for your post, I'm happy to help you.
SSD stands for Solid State Drive. Here's the Wikipedia definition. SSD drive.
Now, for what is in your system go to the Start button and click on run
Type msinfo32 , and go to the section components storage disc.
Lists the disks that you have in your system.
-
Windpws Mail & Wi - Fi
I just installed a TalkTalk wireless router which seems to have installed correctly. However when I try to send and receive e-mail using Windows Mail, she wants to use a made up connection. How can I use the wireless connection? Thank you very much, Dianthus MJ.
Go to tools | Accounts | Mail | Properties | Connection and check or change the connection properties. You will need to remove the account and then add it again, but try first and also check tools | Options | Connections.
Steve
-
Please how can I use a value in a table of the adf in an actionListener to a button I created in a popup and thanks
What is your version of JDev?
Actually your question is not clear to me, but as I understand, it is you the table in the page and you have popup inside this popup you have the button you need when you click on the button to read the value of the selected table row. In the listener action button, so if you can get the current row of the table and after that you can get any attribute of the line as:
DCIteratorBinding iter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("TableIteratorName"); // from pageDef. Row r = iter.getCurrentRow(); Object value1 = r.getAttribute("attribute1"); Object value2 = r.getAttribute("attribute2");
-
Hello
How can I use statistics for all the tables in a schema in SQL Developer? and how long will it take on average?
Thank you
Jay.
Select the connection and right-click on it and select schema statistics collection
-
How can I use lightroom or photoshop on my laptop, when I open it, it says only, I use on two computers and I have already two I have Mac at home.
Hi moving,
You can use Lightroom or Photoshop on two computers using a single license.
If you want to use on the third computer, you should disable any previous machines and turn it then back on the 3rd machine.
You can also consider getting another license or subscription to your other computer.
~ UL
Maybe you are looking for
-
Why am I video ads on the pages of link
My problem starts after I open a Web site, and then click an item in the Web site. First of all, I'll make a video ad (usually an ad for a car), or I'll get a blank page with a firefox notice that firefox will not allow this page open unless I click
-
Re: Emoji &; symbols
MacBook Air v10.11.4 / iTunes 12.3.3 Hello.. How to use Emoji and symbols in the Edition of iTunes menu? How are they used in iTunes on a Mac? Thanks in advance! Carolyn
-
Shift to read register previous integer table
Hey people, New LabVIEW here ask about changing registers. I went through the tutorials and trying to find as much help as I could before posting, but I think that I understand not the functions of register shift as clearly as I should. I need to rea
-
XP Mode "hibernation" and he can't wake up "
I have Windows 7 Pro and that you have installed XP Mode. I run XP Mode several times. All of a sudden, when I try to open the XP Mode I thought that 'Mode could not be restored through host processor or lack of material ast." When I opened the Virtu
-
How to send SMS to an individual or a list of numbers?
Hello I want to send SMS to a particular number or group of numbers. As I had somehow in this link below: Send SMS text Messages I tried with it. But after sending the sms, it is not getting on the particular number. Means, that it is not delivering.