473,379 Members | 1,355 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,379 software developers and data experts.

Difficult count query?

I have two tables: bc_post and bc_message. This is what I have so far:

select bc_post.*, count(bc_message.message_to) responses from
bc_post left join
bc_message on
bc_post.post_id = bc_message.message_topostid
where
bc_post.post_status = '1' and
bc_post.user_id = '1'
group by
bc_post.post_id
This gets correct posts but not correct responses. I want to limit the
responses (the count) to only those where
bc_message.message_to = bc_post.user_id. If I add that statement, I get the
correct responses but I lose any posts
that do not have any messages (which I do not want to do). How do I
retrieve the count (responses) and return 0 if there aren't any?

CREATE TABLE bc_post (
post_id int(10) unsigned NOT NULL auto_increment,
post_date date NOT NULL default '0000-00-00',
post_details text NOT NULL,
post_message text NOT NULL,
post_gender1 varchar(7) NOT NULL default '',
post_gender2 varchar(7) NOT NULL default '',
user_id varchar(25) NOT NULL default '',
post_ip varchar(20) NOT NULL default '',
post_timestamp timestamp(14) NOT NULL,
post_status int(1) NOT NULL default '0',
postgeo_id char(3) NOT NULL default '',
PRIMARY KEY (post_id)
) TYPE=MyISAM;
CREATE TABLE bc_message (
message_id int(10) unsigned NOT NULL auto_increment,
message_topostid int(10) NOT NULL default '0',
message_from varchar(25) NOT NULL default '',
message_to varchar(25) NOT NULL default '',
message_message text NOT NULL,
message_ip varchar(20) NOT NULL default '',
message_timestamp timestamp(14) NOT NULL,
message_status varchar(4) NOT NULL default '0',
PRIMARY KEY (message_id)
) TYPE=MyISAM;

Thank you for any help!!!

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 2448

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

Similar topics

4
by: leegold2 | last post by:
Below is some code from a FULLTEXT search. My question is how do I get a count of the number of rows found by the search? $query="SELECT * FROM balloon_txt WHERE MATCH(access_no, recs_txt)...
5
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report...
6
by: Nicolae Fieraru | last post by:
Hi All, I have a query, Select Count(BoolField) from tblMyTable, Where BoolField = true. If I run the query by itself, it returns the number of true records I want to use the result of that...
5
by: jmartineau | last post by:
Hello, Here is a brief summary: Table 1 = All Accounts - with fields such as Customer ID and Account # Table 2 = Deposit Balance Table - with fields such as Account #, Balance
1
by: sunilkeswani | last post by:
Hi I am still new to access. I want to know how i can build a query which can display results from 4 different columns/fields Like. Field1 Field2 Field3 Field4 1 2 1 ...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
3
by: Auddog | last post by:
I have the following query that works in mysql: select id, order_no, price, count(item_no), sum(price) from production WHERE item_no = '27714' group by item_no; When I setup my query in php,...
4
by: n | last post by:
Hello! Here is a problem I hope you can point me to a solution. It Problem: A teacher needs to know which lesson to teach. A school has a curriculum with 26 lessons, A-Z. For a given class,...
1
by: kummu4help | last post by:
hi, i am using mysql. i have 3 tables with following structures. these are not actual tables i am working on. table A id varchar(16),name varchar(255),InDate datetime table B id...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.