Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Can anyone help me with some SQL queries?
Old 04-09-2008, 05:55 PM Can anyone help me with some SQL queries?
Junior Talker

Posts: 4
Name: andrew
Trades: 0
Hi, ive got some work to do on SQL queries. Ive attempted every question at the bottom, but could do with someone to tell me whether there correct or not and inform me on what im doing wrong.

The scenario is:

A local company that produces machine parts has decided to develop an in-house database system.

They have identified the following tables: -

tblOrders OrderNo, CustomerNo, Date, OrderTotal
tblCustomers CustomerNo, Name, Street, Town, County, Postcode
tblParts PartNo, Description, UnitCost
tblItems OrderNo, PartNo, Quantity, ItemTotal

Create SQL queries to produce the following: -

a) Details of all orders over £1000 sorted by customer
number.

b) A list of all part descriptions and their quantities
appearing on order 39

c) Delete all orders placed by
customers in Wrexham.

d) Archive all orders placed by customer Clarke into a new table called
tblArchive.

e) Increase the price of all parts whose description includes the
word “washer” by 4%.

These are my answer, which im not too sure if they are correct. If any1 could tell me if there correct or not that would be great, thanks.

a)
SELECT *
FROM tblOrders
ORDERBY CustomerNO
WHERE OrderTotal > 1000

b)
SELECT tblParts.PartNo, tblParts.Description, tblItems.Quantity
FROM tblItems INNER JOIN tblParts ON tblItems.PartNo = tblParts.PartNo;
WHERE OrderNo = 39

c)
DELETE tblOrders.*
FROM tblOrders INNER JOIN tblCustomers ON tblOrders.CustomerID = tblCustomers.CustomerID
WHERE Town = “Wrexham”

d)
INSERT INTO tblArchive
SELECT *
FROM tblOrders INNER JOIN tblCustomers ON tblOrders.CustomerID = tblCustomers.CustomerID
WHERE Name = “Clarke”

e)
UPDATE tblParts
SET UnitCost = [UnitCost]*1.04
WHERE Description LIKE “*washer” or Description LIKE “washer*” or
Description LIKE “*washer*”

Please help
andrewc266266 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-09-2008, 09:20 PM Re: Can anyone help me with some SQL queries?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You should NEVER use * in a select query, it slows the query AND can lead to problems should the database be restructured at a later stage.

a) it's ORDER BY (two words) and ORDER has to be AFTER a WHERE clause.

b) looks ok

c) should be "DELETE FROM table" and there is no CustomerID column

d) You are assuming tblArchive already exists, whereas the question calls for a new table to be created.
CREATE TABLE FROM AS ( SELECT fieldlist FROM table WHERE ... );

e) % is the wildcard symbol in SQL. * is only used by MS Access

That's from a look over not real testing done.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-10-2008, 05:23 AM Re: Can anyone help me with some SQL queries?
Junior Talker

Posts: 4
Name: andrew
Trades: 0
thanks
andrewc266266 is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 01:59 PM Re: Can anyone help me with some SQL queries?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You might want to think about not putting tbl as the beginning of each table name.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can anyone help me with some SQL queries?
 

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.50637 seconds with 12 queries