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

Posts: 4
Name: andrew
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
 
When You Register, These Ads Go Away!
     
Old 04-09-2008, 08:20 PM Re: Can anyone help me with some SQL queries?
chrishirst's Avatar
Super Moderator

Posts: 11,872
Location: Blackpool. UK
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!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-10-2008, 04:23 AM Re: Can anyone help me with some SQL queries?
Junior Talker

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

Latest Blog Post:
What Does This Look Like?
Posts: 4,727
Name: John Alexander
You might want to think about not putting tbl as the beginning of each table name.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can anyone help me with some SQL queries?
 

Thread Tools

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

vB 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.12527 seconds with 13 queries