Home » SQL & PL/SQL » SQL & PL/SQL » Re:Confused by these two questions
Re:Confused by these two questions [message #629648] Sat, 13 December 2014 19:59 Go to next message
morrism35
Messages: 10
Registered: December 2014
Junior Member
Need help with these two questions I know I need two join my task table with my priority table but not sure how to get all my tasks
too display. I have included my tables that are invlolved. Thank you in advance. This is my first sql class so please not too advanced stuff I'm struggling enough trying too get a handle on this stuff lol.



1.The users would like to view a list of all tasks but would like to see the Priority name field of the task rather than the Priority ID field. Please create a query that would display all items by task name, due date and priority name with priority name being displayed in UPPER case.
2.The users would like to view a list of all tasks but would like to see the Status name field of the task rather than the Status ID field. Please create a query which would list all items by task name, due date and status name.

Tablename: Tasks
Fieldname Datatype Null Comments
TaskID Number(3) Not null Unique identifier for the table
TaskName Varchar2(20) Not null Name of the task
TaskDesc Varchar2(20) Null Details of the task
DueDate Date Null Task due date
PriorityID Char(1) Null FK to Priority table
StatusID Char(1) Null FK to Status table



Tablename: Priority
Fieldname Datatype Null Comments
PriorityID Char (1) Not null Unique identifier for the table
PriorityName Varchar2(20) Not null Assigns priority level to a task





Re:Confused by these two questions [message #629649 is a reply to message #629648] Sat, 13 December 2014 20:08 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
We are here to help, but we won't do your homework for you. You need to show us what you have tried so far and where you are stuck.
Re:Confused by these two questions [message #629650 is a reply to message #629649] Sat, 13 December 2014 20:15 Go to previous messageGo to next message
morrism35
Messages: 10
Registered: December 2014
Junior Member
select taskname, duedate, upper(priorityname) "PRIORITYNAME" from tasks, priority where tasks.priorityid=priority.priorityid;

This is only returning one of the 4 rows that is in the table. I need all rows in the table.
Re:Confused by these two questions [message #629651 is a reply to message #629650] Sat, 13 December 2014 20:15 Go to previous messageGo to next message
morrism35
Messages: 10
Registered: December 2014
Junior Member
For both questions one is asking for priority name instead of priorityid and the other is asking for priority name instead of priorityid.
Re:Confused by these two questions [message #629652 is a reply to message #629651] Sat, 13 December 2014 20:41 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/
Re:Confused by these two questions [message #629653 is a reply to message #629650] Sat, 13 December 2014 20:43 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
morrism35 wrote on Sat, 13 December 2014 18:15
select taskname, duedate, upper(priorityname) "PRIORITYNAME" from tasks, priority where tasks.priorityid=priority.priorityid;

This is only returning one of the 4 rows that is in the table. I need all rows in the table.


Given what you have provided, this is the correct way to join the tables. If you are only getting one row, then there must only be one row that matches. If you want the non-matching rows as well, then you can use an outer join:

SELECT priority.taskname, priority.duedate, UPPER (tasks.priorityname)
FROM   priority, tasks 
WHERE  priority.priorityid = tasks.priorityid(+);


You may also want to add an ORDER BY clause.

It might help if you provide create table and insert statements for your data or at least the results of the following:

SELECT * FROM tasks;
SELECT * FROM priority;
Re:Confused by these two questions [message #629654 is a reply to message #629653] Sat, 13 December 2014 20:57 Go to previous messageGo to next message
morrism35
Messages: 10
Registered: December 2014
Junior Member
So you are saying I would need a outer join and yes I want all rows in the task table. I did try an order by clause with my original code that I posted but it still only returned one row . Is there a way to copy the text from a sql plus window?

.
Re:Confused by these two questions [message #629655 is a reply to message #629654] Sat, 13 December 2014 21:05 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Is there a way to copy the text from a sql plus window?


have you ever heard about COPY & PASTE?
Re:Confused by these two questions [message #629656 is a reply to message #629654] Sat, 13 December 2014 21:05 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
morrism35 wrote on Sat, 13 December 2014 18:57
So you are saying I would need a outer join and yes I want all rows in the task table. I did try an order by clause with my original code that I posted but it still only returned one row . Is there a way to copy the text from a sql plus window?

.


Yes, you need the outer join. You need to make sure that the (+) is on the tasks table.

The ORDER BY clause does not affect the number of rows, just the order in which they are displayed, which seems to be something the problem is asking for.

Yes, you can copy the text from your SQL*Plus window. Left mouse clock on the little icon in the upper left corner of the bar on the top of the window. A drop-down list should appear. Select edit, then select all. Go back to the little icon, left click, select edit, then select copy. Come to the forum, click on the reply window, then hold down your ctrl key and press the V key.
Re:Confused by these two questions [message #629665 is a reply to message #629656] Sun, 14 December 2014 02:31 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
To get full marks, ANSI join syntax might be better then the (+) syntax. I think most teachers would penalize use of proprietary constructs in a SQL class.
Re:Confused by these two questions [message #629672 is a reply to message #629654] Sun, 14 December 2014 07:10 Go to previous messageGo to next message
EdStevens
Messages: 1376
Registered: September 2013
Senior Member
morrism35 wrote on Sat, 13 December 2014 20:57
Is there a way to copy the text from a sql plus window?

.


Unless you are running 'sqlplusW.exe' there is no such thing as a "sql plus window". There is only a command process window, under which you could run any number of programs that use a command line interface. You simply happen to be running sqlplus. You copy text out of it the same way you copy text out of it when any other program is running in it. Right-click on the little icon in the upper left corner. From there it should be obvious what you need to do.
Re:Confused by these two questions [message #629680 is a reply to message #629672] Sun, 14 December 2014 13:09 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
EdStevens wrote on Sun, 14 December 2014 05:10
morrism35 wrote on Sat, 13 December 2014 20:57
Is there a way to copy the text from a sql plus window?

.


Unless you are running 'sqlplusW.exe' there is no such thing as a "sql plus window". There is only a command process window, under which you could run any number of programs that use a command line interface. You simply happen to be running sqlplus. You copy text out of it the same way you copy text out of it when any other program is running in it. Right-click on the little icon in the upper left corner. From there it should be obvious what you need to do.


Right click? I have always left clicked. After reading your post, I tested and found you can do either. So, apparently, you just need to click and either left or right will do.
Re:Confused by these two questions [message #629681 is a reply to message #629680] Sun, 14 December 2014 13:29 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
So, apparently, you just need to click and either left or right will do.


Or the opposite for left-handed people. Razz

Previous Topic: oracle procedure compile syntax check
Next Topic: Updating a column in many tables
Goto Forum:
  


Current Time: Wed Apr 24 19:13:49 CDT 2024