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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 13th, 2003, 01:03 PM
tazg101 tazg101 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 3 tazg101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Simple Mysql Query

I have 2 tables makes,products

makes
-------
makeid primary
name

products
----------
prod_id primary key
makeid
model_no
description
RRP

in the products i have set it so it refers to a make number in the make tables.

How do i do a query so i can say display all products with a make ID of 5 etc.?

name

Reply With Quote
  #2  
Old March 16th, 2003, 12:50 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
You can do this:

Code:
SELECT * FROM products WHERE makeid = 5;


Because your products table has the makeid reference, the 5 will be stored in that field.

If you want to display all information, you can try this:

Code:
SELECT * FROM products, names WHERE products.makeid = names.makeid;


Try those queries, and you'll see the difference in the results.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old March 16th, 2003, 05:27 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
you can also use inner joins, which i think are a bit faster then normal joins.

PHP Code:
 SELECT FROM products INNER JOIN makes ON products.makeid makes.makeid 


Always try to use inner joins as they are usually faster

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Simple Mysql Query


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 3 hosted by Hostway