Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 19th, 2003, 06:33 PM
myraleen myraleen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Ottawa, Ontario, Canada
Posts: 123 myraleen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to myraleen Send a message via AIM to myraleen
Complex query and join

I have a table of subjects that a system user can view that is set up already. I have added another column to this.

The table is broken down with php variables, and the structure is set up in an inc file.

So there are $table, $fields[], $select_options, $where_clause, $order_by_clause variables.

The data, or how to display it, is done with an external processing function, calling each field and echoing either the data or a non breaking space. It uses switch case: to do this.

This is how the query is looking normally when it all goes together nicely:

php Code:
Original - php Code
  1.  
  2. SELECT distinct tb1.div, tb2.name, tb1.dob, tb1.level WHERE tb1.div = tb2.div AND tb1.control='A' AND tb2.control = 'A' ORDER BY tb1.div


This works, and displays a nice table, the first column, the div is displayed as a link to view more information on the 'subject' of the query.

Now came my problem.

I added the final column. Which comes from a third table. (This column ideally would display how many books each subject had.) The table it comes from however, has also got a div field, and a control field. And both of these need to be checked for the query to display proper results.

I have tried a join clause

php Code:
Original - php Code
  1.  
  2. LEFT JOIN tb3 ON tb1.div = tb3.div


and i also tried simply adding an additional field variable:
php Code:
Original - php Code
  1.  
  2. $fields[] = "tb3.control";


Ideally though, i'd like to use the

php Code:
Original - php Code
  1.  
  2. $fields[] = "tb3.div";


Anyways... I'm trying not to confuse you anymore then I am.

What is happening, is if i do it with the control, i am getting too many rows of the same div, and if i add something to the where clause, it doesn't display them if they are not in the tb3.

I am sorry this sounds so confusing, perhaps it is my mind state.

Basically, I want information from 3 tables. Two tables contain the same field names, I want the div fields to all match up. However even if there is no div in the third table, the information should still be displayed.

Hope someone can make sense of this.

:S

Reply With Quote
  #2  
Old November 19th, 2003, 07:11 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Complex query and join

Too confusing?

Well that's ok i got it.

I kept the join by, and added a group by.


Now i just have to figure out the count part.

thanks anyways!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Complex query and join


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