473,781 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

having count() trouble in a GROUP BY clause

The idea I'm trying to get at is that I want the tag info for the tag
"photograph y", and I want the date, and I want a count of any comments
a tag may have. This following query gets back all the info I want,
provided the tag has at least one comment. If It doesn't have any
comments, it doesn't show up in the return. But if it has a count of
zero, I just want it to come back with a count of zero, I don't want it
to disappear from the return. I'm not sure what I'm doing wrong, thogh
I'm no good at SQL so it is probably something obvious.

I've created for myself a test situation where I know there are 8
entries that have the tag "photograph y" and 3 of them have comments. If
I drop this line from the WHERE clause:

AND tagCloud.id = comments.belong sToWhichPage

then I get 8 entries in return, which is the correct number, but they
are all the same entry. The same entry 8 times that is. But if I
include the line above, then I only get the 3 entries that have
comments

The query and the table structure is below, any help is greatly
appreciated.
SELECT tagCloud.id, tagCloud.url, tagCloud.item, tagCloud.headli ne,
tagCloud.descri ption,
tagCloud.tag1, tagCloud.tag2, tagCloud.tag3, tagCloud.tag4,
tagCloud.tag5,
tagCloud.tag6, visitors.date,
comments.belong sToWhichPage, count( * ) howManyComments
FROM tagCloud, visitors, comments
WHERE tagCloud.visito rId = visitors.id
AND tagCloud.id = comments.belong sToWhichPage
AND ( tag1 = 'photography' || tag2 = 'photography' || tag3 =
'photography' || tag4 = 'photography' || tag5 = 'photography' || tag6
= 'photography' )
GROUP BY belongsToWhichP age
ORDER BY tagCloud.id DESC;

CREATE TABLE `comments` (
`id` int(11) NOT NULL auto_increment,
`mainContent` text NOT NULL,
`url` varchar(255) NOT NULL default '',
`email` varchar(255) NOT NULL default '',
`name` varchar(255) NOT NULL default '',
`visitorId` int(11) NOT NULL default '0',
`belongsToWhich Page` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT= 21 ;

# --------------------------------------

CREATE TABLE `tagCloud` (
`id` int(11) NOT NULL auto_increment,
`url` varchar(255) NOT NULL default '',
`item` varchar(255) NOT NULL default '',
`headline` varchar(255) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`tag1` varchar(255) NOT NULL default '',
`tag2` varchar(255) NOT NULL default '',
`tag3` varchar(255) NOT NULL default '',
`tag4` varchar(255) NOT NULL default '',
`tag5` varchar(255) NOT NULL default '',
`tag6` varchar(255) NOT NULL default '',
`fileType1` varchar(20) NOT NULL default '',
`fileType2` varchar(20) NOT NULL default '',
`email` varchar(255) NOT NULL default '',
`visitorId` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT= 20 ;

# ----------------------------------------

CREATE TABLE `visitors` (
`id` int(11) NOT NULL auto_increment,
`date` int(11) NOT NULL default '0',
`ipAddress` varchar(15) NOT NULL default '',
`hostname` varchar(255) NOT NULL default '',
`machineId` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT= 893 ;

Dec 14 '05 #1
0 3228

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

Similar topics

0
1460
by: Graham Simms | last post by:
I have tried to run a query where the reuslts are restricted by a HAVING clause with 2 conditions, but the second condition seems to be ignored. for example SELECT userid, AVG(position) FROM `table1` WHERE (status='finished') GROUP BY userid HAVING (COUNT(*) >= 4 AND AVG(position) < 5.5) returns exactly the same as
18
9766
by: war_wheelan | last post by:
I am very new to Transact-SQL programming and don't have a programming background and was hoping that someone could point me in the right direction. I have a SELECT statement SELECT FIXID, COUNT(*) AS IOIs and want to ORDER BY 'IOI's'. I have been combing through the BOL, but I don't even know what topic/heading this would fall under. USE INDII SELECT FIXID, COUNT(*) AS IOIs FROM . GROUP BY FIXID
22
12494
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=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient moConn.Mode = adModeReadWrite' or using default...same result
3
3112
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, I use: $query2 = "SELECT id, order_no, price, count(item_no) as count from production where item_no = '27714";
0
1160
by: asearle | last post by:
Dear all, I have some xslt reporting functionality that currently uses generate-id to group data. This works fine but is very slow. While googling, I found that the 'count()' clause can do the same thing but faster and so have been experimenting with that. My original code was the following: <xsl:for-each select="rep_base)]">
8
944
by: C10B | last post by:
hi, I have a table with several million rows. Each row is simply the date and time a certain page was viewed. eg page1 1-1-00 page2 2-1-00 page1 16-1-00 page1 17-1-00
1
3484
by: vanandwiz | last post by:
Please find the code below. SELECT COMPANY.NAME, COUNT(ITEM.ID) FROM ITEM, COMPANY WHERE ITEM.COMPANYID = COMPANY.ID GROUP BY ROLLUP(COMPANY.NAME)
10
2257
by: marting | last post by:
Before I throw my new expensive laptop out of the window! I'm stuck on getting my joins right with the correct amount in a column count. After speaking with someone a few weeks back, they suggested I redesigned my database to use more tables of info. Before I had 1 table for image information, now I have 9 and it's getting very, very confusing... especially as I don't know much about joins...! I am using ASP, MySQL, IIS and VBScript. ...
2
10414
by: Jack | last post by:
Hi, Performance-wise, is there a difference between these 2 clauses? I assume a large database... 1) With the WHERE clause: Select FLD1, FLD2, FLD3 From myFile Where FLD1 = 1 And FLD2 = 1
0
9639
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10308
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
10143
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
10076
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
9939
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...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
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
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.