Exforsys

Free Training

Question 9 is the only one correct, rest of them syntax errors..Can anyone help me

This is a discussion on Question 9 is the only one correct, rest of them syntax errors..Can anyone help me within the MySQL forums, part of the Database category; USING:ORACLE 9i For each of the following tasks, determine (a) the SQL statement needed to perform the stated task using ...

Go Back   Exforsys > Database > MySQL

Exforsys.com

  #1 (permalink)  
Old 10-04-2006, 04:28 PM
Junior Member
 
Join Date: Oct 2006
Posts: 1
butterflyTee is on a distinguished road
Angry Question 9 is the only one correct, rest of them syntax errors..Can anyone help me

USING:ORACLE 9i

For each of the following tasks, determine (a) the SQL statement needed to perform the stated task using the traditional approach and (b) the SQL statement needed to perform the stated task the JOIN keyword.

Code:
A list that displays the title of each book & the name and phone number of the person at the publisher's office whom you would need to contact to record each book.

SELECT title, name, customer
FROM books NATURAL JOIN publisher
WHERE books.pubid = publisher.pubid
AND c.books = record

Determine which orders have not yet shipped & the name of the customer that placed each order. Sort results by dates on the orders was placed.

SELECT lastname, firstname, order#
FROM customers c, JOIN orders, o
WHERE c.customer# = o.customer#(+)
ORDER BY c.customer#;

List the customer number & names of all individuals have purchased books in the Fitness Category.

SELECT title, firstname, lastname 
FROM customers,JOIN orders, orderitems, books 
WHERE customers.customer#=orders.customer# 
AND orders.order#=orderitems.order# 
AND orderitems.isbn=books.isbn 
ORDER BY title = (‘Fitness’) 


Determine book Jake Lucas has purchased.

SELECT lastname, firstname, order# 
FROM customers c OUTER JOIN orders o
WHERE lastname = 'Lucas' and firstname = 'Jake' 
ON c.customer# = o.customers# 
ORDER BY c.customers# = (‘Jake Lucas’) 



Determine profit of each book sold to Jake Lucas. Sort results by date of order. If more than 1 book was ordered, have results sorted by profit amount in descending order.

SELECT lastname, firstname, order# 
FROM customers, JOIN orders, orderitems, books 
WHERE "Profit" 
COUNT() and GROUP BY 
ORDER BY "Profit" desc; 



Which book was written by an author with the last name Adams ?

SELECT title, authorid 
FROM books, JOIN bookauthor 
WHERE author upper(bookauthor.lastname) = ' ADAMS ' 


What gift will a customer who orders the book Shortest Poems receive?

SELECT title, customer, gift 
FROM books, JOIN promotion ('Shortest Poem') 
ON retail BETWEEN minretail AND maxretail 



Identify the author(s) of books ordered by Becca Nelson


SELECT lastname, firstname, title, customers authorid 
FROM books,JOIN customers, bookauthor 
WHERE customers
ORDER BY ('Becca Nelson') 



Display list of all books in BOOKS table. If a book has been ordered by a customer, also list the corresponding order number(s) & state which the customer resides.

SELECT title, o.order#, state
FROM books b LEFT JOIN orderitems i 
ON b.isbn=i.isbn
left JOIN orders o 
ON o.order#=i.order# 
left JOIN customers c 
ON o.customer#=c.customer#
ORDER BY title;



Produce a list of all customers live in the state of Florida & ordered books about computers.

SELECT lastname, firstname, state, books, order# 
FROM state s,JOIN customers c, orders o (' Florida ') 
WHERE c. customer# AND s. customer# = o. customer#
ON o.customer#=c.customer#
ORDER BY ('Computers')
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-05-2007, 09:34 AM
Senior Member
 
Join Date: Apr 2006
Posts: 145
Rahulbatra is on a distinguished road
The first question has syntax error on the part of
c.books = record
defined in
SELECT title, name, customer
FROM books NATURAL JOIN publisher
WHERE books.pubid = publisher.pubid
AND c.books = record

The c.books = record is not defined in the query and usage of this results in error.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-05-2007, 10:48 AM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
In the second query placed as
SELECT lastname, firstname, order#
FROM customers c, JOIN orders, o
WHERE c.customer# = o.customer#(+)
ORDER BY c.customer#;

The syntax error lies in the part of JOIN orders, o. It must be written as
JOIN orders o
There must not be a comma placed between table name orders and alias name o and so the correct query for execution must be as below:
SELECT lastname, firstname, order#
FROM customers c, JOIN orders o
WHERE c.customer# = o.customer#(+)
ORDER BY c.customer#;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-18-2007, 03:02 PM
Senior Member
 
Join Date: Apr 2006
Posts: 138
Ralph is on a distinguished road
The third query given is as below:

SELECT title, firstname, lastname
FROM customers,JOIN orders, orderitems, books
WHERE customers.customer#=orders.customer#
AND orders.order#=orderitems.order#
AND orderitems.isbn=books.isbn
ORDER BY title = (‘Fitness’)

The syntax error occurs in the place JOIN orders. The joins would have been implemented in the table level for all tables using the concept of referential integrity by defining primary key and foreign key on all tables. JOIN must not be specified explicitly by using word JOIN in the syntax. So the corrected query must be as below:

SELECT title, firstname, lastname
FROM customers,orders, orderitems, books
WHERE customers.customer#=orders.customer#
AND orders.order#=orderitems.order#
AND orderitems.isbn=books.isbn
ORDER BY title = (‘Fitness’)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:13 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.