Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 18th, 2004, 05:08 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default joining 3 tables

hello
i have these tables

properties
 id
 pname
 areaid
 type

areas
 areaid
 aname

prefectures
 preid
 pname

How can i select the rows from properties that are located in preid=3 (for example) and are of type '2' (again for example)

any help appreciated

Reply With Quote
  #2 (permalink)  
Old September 20th, 2004, 02:26 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , India.
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

Explain about your table relations... between 1 & 3 or 2 & 3


Reply With Quote
  #3 (permalink)  
Old September 20th, 2004, 05:22 AM
Registered User
 
Join Date: Sep 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, i forgot a field in areas table !

properties table is related to areas table using the areaid field in properties [many] and areaid field in areas [one]

then, areas table is related to prefectures table using the preid field in areas [many] and preid field in prefectures [one]

the tables

properties
 id
 pname
 areaid
 type

areas
 areaid
 aname
 preid

prefectures
 preid
 pname


Reply With Quote
  #4 (permalink)  
Old September 28th, 2004, 02:55 AM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

Select Pro.* from Properties Pro Inner Join Areas AR on
Pro.areaid=Ar.areaid Inner Join Preference Pre on
AR.Preid=Pre.Preid
Where Pre.Preid= 3 AND
Pro.Type= 2

I feel that u r having redundant Preid colum. In Area Table there is a preid. If so, u don't have to Join Third table Preference. The Query can be :-

Select Pro.* from Properties Pro Inner Join Areas AR on
Pro.areaid=Ar.areaid Where AR.Preid= 3 AND
Pro.Type= 2


Hope this helps

B. Anant
Reply With Quote
  #5 (permalink)  
Old September 29th, 2004, 11:32 PM
Friend of Wrox
 
Join Date: Sep 2004
Location: New Delhi, Dekhi, India.
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

HI again,

I am usd to use T-SQL so I am sorry. Please avoid using INNER word to Join. just use JOIN and at the end of Query a semicolon is require with MySql.

B. Anant
Reply With Quote
  #6 (permalink)  
Old March 24th, 2006, 09:52 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello all
I'm a novice in SQL and want to do something like this:

I have 3 tables with the fields above
<TRUKS>
   TRAILER_NO (char)
   DATE (date)
   STATE (CHAR)
<TESTS>
   TRAILER_NO (char)
   PDT30 (float)
   PDT60 (float)
   REJECTED (boolean)
   PROTECT (boolean)
<SUPLIER>
   TRAILER_NO (char)
   DT30 (float)
   DT60 (float)
   PROTECT (boolean)

so i want to join these 3 tables whit fields TRUKS.TRAILER_NO, TESTS.PDT30, TESTS.PDT60, SUPLIER.DT30, SUPLIER.DT60, who meet the criteria as follows:
1-TRUKS.TRAILER_NO=TESTS.TRAILER_NO OR
  TRUKS.TRAILER_NO=SUPLIER.TRAILER_NO
2-TRUKS.DATE>=any_date1 AND TRUKS.DATE<=any_date2
3-TRUKS.ESTADO="F"
4-TESTS.REJECTED=False AND TESTS.PROTECT=False
5-SUPLIER.PROTECT=False

an example
<TRUKS>
TRAILER_NO DATE STATE
   21 xx F
   22 xx F
   23 xx F
   24 xx F
<TESTS>
TRAILER_NO PDT30 PDT60 REJECTED PROTECT
   21 x0 x1 False False
   22 x2 x3 False False
   22 x4 x5 True False
   24 x6 x7 False False
<SUPLIER>
TRAILER_NO DT30 DT60 PROTECT
   21 y0 y1 False
   22 y2 y3 False
   23 y4 y5 False

so the result i want is
TRAILER_NO PDT30 PDT60 DT30 DT60
   21 x0 x1 y0 y1
   22 x2 x3 y2 y3
   23 y4 y5
   24 x6 x7

help appreciated
Thank you all

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help joining tables and restricting records bren582 SQL Server 2005 3 January 18th, 2008 02:45 PM
joining tables pit_bait SQL Language 2 September 28th, 2007 07:29 AM
Joining Three Tables Alexpizzoferro Classic ASP Databases 5 September 1st, 2006 04:08 PM
problem joining tables using vfpoledb in c# ACE2084 ADO.NET 2 April 1st, 2006 03:10 AM
Joining two tables rajustha SQL Server 2000 1 December 7th, 2003 07:38 AM



All times are GMT -4. The time now is 08:27 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.