MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 16th, 2006, 04:55 PM
highlander2k5 highlander2k5 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2005
Posts: 14 highlander2k5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 0
Query Problem

I'm new to queries and I'm having trouble solving this problem. Here are the tables I'm working with (the name of the table is listed at the top of each).

customer
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| cust_id | int(5) | NO | PRI | NULL | |
| surname | varchar(50) | YES | | NULL | |
| firstname | varchar(50) | YES | | NULL | |
| initial | char(1) | YES | | NULL | |
| title_id | int(3) | YES | | NULL | |
| address | varchar(50) | YES | | NULL | |
| city | varchar(50) | YES | | NULL | |
| state | varchar(20) | YES | | NULL | |
| zipcode | varchar(10) | YES | | NULL | |
| country_id | int(4) | YES | | NULL | |
| phone | varchar(15) | YES | | NULL | |
| birth_date | char(10) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+

items
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| cust_id | int(5) | NO | PRI | NULL | |
| order_id | int(5) | NO | PRI | NULL | |
| item_id | int(3) | NO | PRI | NULL | |
| wine_id | int(4) | NO | | NULL | |
| qty | int(3) | YES | | NULL | |
| price | decimal(5,2) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+

orders
+--------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+-------------------+-------+
| cust_id | int(5) | NO | PRI | NULL | |
| order_id | int(5) | NO | PRI | NULL | |
| date | timestamp | YES | | CURRENT_TIMESTAMP | |
| instructions | varchar(128) | YES | | NULL | |
| creditcard | char(16) | YES | | NULL | |
| expirydate | char(5) | YES | | NULL | |
+--------------+--------------+------+-----+-------------------+-------+

titles
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| title_id | int(2) | NO | PRI | NULL | |
| title | char(10) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+

wine
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| wine_id | int(5) | NO | PRI | NULL | |
| wine_name | varchar(50) | NO | MUL | NULL | |
| wine_type | int(2) | NO | | NULL | |
| year | int(4) | NO | | NULL | |
| winery_id | int(4) | NO | MUL | NULL | |
| description | blob | YES | | NULL | |
+-------------+-------------+------+-----+---------+-------+

wine_type
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| wine_type_id | int(2) | NO | PRI | NULL | |
| wine_type | varchar(32) | NO | | NULL | |
+--------------+-------------+------+-----+---------+-------+

wine_variety
+------------+--------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------+------+-----+---------+-------+
| wine_id | int(5) | NO | PRI | 0 | |
| variety_id | int(3) | NO | PRI | 0 | |
| id | int(1) | NO | | 0 | |
+------------+--------+------+-----+---------+-------+

What I'm trying to do is find a query that lists the 10 most popular wines among customers with the title of 'Mr' where I print out the name of each wine, the type and year of each wine, and the number of customers titled 'Mr' who purchased that wine. This is what I have so far for my query, but I don't know where to go from here: select wine_name, wine_type.wine_type, year from wine, wine_type, titles where title = 'Mr'

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Query Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT