473,804 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mulitple Table Query Help

I'm not sure the follow multiple table query is the right way to do
what I need to do although it seems to be working:

$php_SQL = "SELECT * ".
"FROM basics, personal, photos ".
"WHERE basics.member_n ame = personal.member _name ".
"AND basics.member_n ame = photos.member_n ame ".
"AND basics.account_ creation_date >= DATE_SUB(NOW(),
INTERVAL 30 DAY)";

I primarily need to return a resultset for all member_names (they are
index key and unique) filtered for the last 30 days on the
basics.account_ creation_date - this 30 day thing is working fine.

I need to access various other table fields and display this data on
the web page - member_name is the common key for all tables - this all
seems to be working fine as I have 8 test records and can manually
track and see that it is working - the problem is that I need to add a
4th table and in doing so, the resultset breaks and returns just one
record - I am adding an online table with a field called is_online
which is set to 'yes' if the member is online but the following query
returns just the one record of the online member:

$php_SQL = "SELECT * ".
"FROM basics, personal, photos, online ".
"WHERE basics.member_n ame = personal.member _name ".
"AND basics.member_n ame = photos.member_n ame ".
"AND basics.member_n ame = online.member_n ame ".
"AND basics.account_ creation_date >= DATE_SUB(NOW(),
INTERVAL 30 DAY)";

It seems to me this should be an easy thing to just add the 4th table
but since this breaks the query now I'm wondering if this query
structure is even built right?

Any help would be greatly appreciated...

Jul 16 '05 #1
1 2528
Thanks for the comments -

1. Yes I figured out that my online table was wrong, it needed all
member_names in it - as you pointed out - that was indeed why it was
resulting in one row - so I got that fixed and it works as expected
now. Previously I was using that online table in another way and
changed the way I use it and didn't realize it needed all the other
member names in it.

2. Yes, I wasn't sure about my post being in here - sometimes help is
given in php (although not in this case) on mysql issues - but thanks
for the comment and thanks for the table help.
On Wed, 03 Sep 2003 02:05:44 +0200, Bruno Desthuilliers
<bd***********@ removeme.free.f r> wrote:
Ralph Freshour wrote:
I'm not sure the follow multiple table query is the right way to do
what I need to do although it seems to be working:

$php_SQL = "SELECT * ".
"FROM basics, personal, photos ".
"WHERE basics.member_n ame = personal.member _name ".
"AND basics.member_n ame = photos.member_n ame ".
"AND basics.account_ creation_date >= DATE_SUB(NOW(),
INTERVAL 30 DAY)";

I primarily need to return a resultset for all member_names (they are
index key and unique)
filtered for the last 30 days on the
basics.account_ creation_date - this 30 day thing is working fine.

I need to access various other table fields and display this data on
the web page - member_name is the common key for all tables - this all
seems to be working fine as I have 8 test records and can manually
track and see that it is working - the problem is that I need to add a
4th table and in doing so, the resultset breaks and returns just one
record - I am adding an online table with a field called is_online
which is set to 'yes' if the member is online but the following query
returns just the one record of the online member:

$php_SQL = "SELECT * ".
"FROM basics, personal, photos, online ".
"WHERE basics.member_n ame = personal.member _name ".
"AND basics.member_n ame = photos.member_n ame ".
"AND basics.member_n ame = online.member_n ame ".


<OT>
This line above tells the DB to inner-join basics and online on the
member_name field. So if there is only one record in online, it is quite
normal that you only get this record in your resultset.

I guess that you've got corresponding records in personal and photos for
all records in basics, else you would have spot the problem sooner.

Now the result may not be what you expect, but as we dont know for sure
what you expect, it's hard to tell you how you could get it.

BTW, could it be possible that there is a little mistake in your db schema ?

You state that :
I am adding an online table with a field called is_online
which is set to 'yes' if the member is online but the following query
returns just the one record of the online member:


If your schema is something like :
basics(*member _name*, ...)
online(*member _name*, yes_no)

then it's broken. You should have a field 'online' in basics, and no
online table table.

Or did I miss something ?
</OT>

Oh, and BTW, your question is a bit off-topic here, since it has nothing
to do with php !-)

comp.databas es would have been a better place IMHO.

Bruno


Jul 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
6220
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
2
1663
by: Ray | last post by:
I just have a brief idea of this approach and would like to hear a few words from experts here. I have medium level of programming in Access. In fact, I would like to build a simple database to replace a spreadsheet showing the scores of the suppliers. Initially, I need to build a form like multiple choice Q & A sheet for the judges to input the scores and then generate a report showing the score of each element and total score like the...
3
1540
by: Tracy | last post by:
Hi I'm hoping this is a problem just because I'm a beginner at Access, and so someone can help I have created a database of companies, with a subform for contacts. (seperate tables) It worked perfectly until I got more than one contact for a company!
5
2319
by: Dave H | last post by:
I have an asp:listbox, allowing multiple selections, is there a quick check to see if there's more than one selected, or do I need to go through the whole list? Thanks, Dave
7
2979
by: CheezIt2831 | last post by:
hello, I have 5 tables(Alpha, Bravo, Charlie, Service, Trans). What i am trying to do is be able to select a start date and ending date for a report and include fields from the 5 tables. this is my code: SELECT , , , , FROM UNION SELECT , , , , FROM UNION SELECT , , , , FROM UNION SELECT , , , , FROM
14
2172
by: bcap | last post by:
Hello, I really would apprciate help! =) What I want to do is be able to change the status of mulitple records using a drop down and a checkbox. I have a drop down called "ChangeStatus" with the values to change the status to Pending, Accepted, Declined, Cancelled, Completed.
2
2649
by: julie18881 | last post by:
I may be being really stupid here, i have spent the last 3 hours looking round your site and some other for answers to my problem, but have not had much luck (possibly cuase my brain just isn't working today) I have EasyPHP2.0b1 Apache/MySQL server installed on my Windows XP(SP2) machine. This runs Apache 2.2.3, MySQL 5.0.27 and PHP 5.2.0 I have a PHP code filled listbox, which allows multiple selections. Actual Values are "rcd_no, cn_no"...
1
1367
by: TheNewBoy | last post by:
Hi All. I am new to this forum... Don't know how to start but here it goes.... I am writing in VB.net a program with one form, yet mulitple textboxes. the data appears in each text box as A1, A2, A3, A4, A5 The database CANDYSHOP has a table CANDYSHOP with each column as
0
5018
by: Jay Douglas | last post by:
Hello, I've found some posts on creating dynamic WHERE clauses in LINQ to SQL using predicate builders and extending lamda expressions. One issue with these posts is all the examples only use a single customer table. I'm need a way to dynamically create a where clause using multiple tables. None of the tables I'm using have references in the LINQ designer so the JOIN operator is required. If I were to hard type out the query in...
0
9593
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.