473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

MySQL multi table bug

Hello,

I am currently having a bug with a MYSQL query for an online calendar I am writing. I have been looking at this bug for a couple days now and am still not able to figure out why it continues to do it.

I have 2 tables called calendar_users and comments

calendar_users has these fields in it: user_id, dispname, username, password, color, login

comments has these fields in it: comment_id, orig_user_id, month_posted, day_posted, year_posted, comment, upd_user_id


Here is the query im looking at right now:

Expand|Select|Wrap|Line Numbers
  1. $query = "
  2. SELECT DISTINCT a.color, o.comment 
  3. FROM calendar_users a, comments o 
  4. WHERE o.month_posted='" . $month . "' 
  5. AND o.day_posted='" . $date . "' 
  6. AND a.user_id=o.upd_user_id";
  7.  
k.. the issue I am having with this query is there are 2 comments posted on the same date by 2 different users. However on the page itself is shows 4 comments: the first one, the second one, the first one again, the second one again. The comments are at least matching up with the color chosen for them so I know that the query is halfway working, but am unable to fix the repeating issues. Any ideas you can give?
Oct 15 '08 #1
2 1512
Atli
5,058 Expert 4TB
Hi.

Try be more specific with your joins. The way you use them, all columns in table A are simply joined with all columns from table B.

Like, for example:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM `calendar_user` AS u
  3. INNER JOIN `comments` AS c
  4.     ON u.user_id = c.upd_user_id
  5.  
This will filter the data *before* the where clause is applied, removing possible JOIN duplications.

If this doesn't work, please show us the exact table structure of your tables (the CREATE statements, preferably), and an example of the data that you are working with. Without that we are just guessing, really.

P.S
Please use [code] tags when posting your code examples.

[code] ...Code goes here... [/code]

Thank you.

And I hope you don't mind that I added a few new-lines to your query as well, just so it would be easier to read. Having it all in one line makes it very hard to read.

Moderator
Oct 15 '08 #2
Thank you for the help with the query issue. While the suggestion you gave did fix the bug in the query when checked with the phpMyAdmin query window, the problem did persist on the page itself. After tracking down the issue in my php code, I did finally find the problem on the page. Thank you again for your help. :)
Oct 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Vic | last post by:
Hi all, When I test the Delete multi table function in MySQL, DELETE table_name ...] FROM table-references I accidentally delete all data in one table. All data in that table are gone...
0
by: packrat | last post by:
I am attempting to build a Bugzilla server on OS X. All of this is new to me, working with the Perl, MySQL, and Bugzilla, so I have been banging my head often. Software error: When I run the...
3
by: saracen44 | last post by:
Hi I have MyISAM tables When I'm deleting parent I want to delete children in the same time. How can I do It? What are possibilities? Thanks
2
by: Nick name | last post by:
Hello, I am creating a Database Architecture and there is a volume problem with MySQL. My tables are quite simple. Problem is they will record million of lines. Within 10 seconds, MySQL...
0
by: Jim Whitaker | last post by:
Expand full for viewing... I have a parent/child table. The basic setup is as follows: The parent table is called load sheet. It has fields such as Tripno, carrier, loaddate, etc. The child...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
0
by: Bucker | last post by:
Could someone view the following that I copied from phpMyAdmin and tell me from the statistics if are server is running OK? Does it look like we will have problems as more people hit our server?...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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...

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.