Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 6th, 2006, 06:06 AM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple subqueries?


I'm having a bit of a problem with a MySql query to (I think) three tables. I "inherited" the system from another, somewhat more experienced MySQL programmer, so I don't find it all that easy to navigate in.

Problem is this:

I have three tables, A, B and C.

I want the number of occurrences (Count) in Table A of Person = X. But it must be conditioned by a certain type of events. In Table A is an A.Eventno (corresponding to B.IDno). In Table B are the details for that event. One of the details is B.MasterEvent (corresponding to C.IDno). However, the details for the MasterEvent is in Table C, and the specific sub-types are in C.SubType.

What I want is all Person = X where the A.Eventno is of certain C.SubTypes.

Hope I'm making myself clear here.

I have read a bit about subqueries, but somehow the exact structuring for a problem like this one has escaped me until now...

Hope one of you can give me a hand with this.

-Thomas

Thomas Frandzen
 
Old October 24th, 2006, 05:30 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Something like:
Code:
SELECT COUNT(person.id) 
  FROM A,B,C 
 WHERE person='X' 
   AND B.PersonID=A.id 
   AND B.MasterEvent=C.IDno 
   AND C.SubType IN ('type1','type2','type3');
?


--
Don't Stand on your head - you'll get footprints in your hair
                                           http://charlieharvey.org.uk
                                              http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
which is faster Subqueries or Views? lakshminal SQL Language 0 May 1st, 2008 11:20 PM
SubQueries debbiecoates SQL Server 2000 5 October 22nd, 2007 02:04 PM
SubQueries in a select statement in dataset madhusrp Reporting Services 1 February 22nd, 2007 03:03 AM
Trouble with Subqueries, am I going mad. kim3er SQL Server 2000 3 April 10th, 2005 02:13 PM
subqueries mgdts SQL Server DTS 0 July 28th, 2003 01:13 PM





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