473,405 Members | 2,141 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,405 software developers and data experts.

mysql question and a really bad joke

Lets say I have 2 tables, tbl_topics and tbl_lessons:
tbl_topics

topicID
INT

parentID
INT

Title
VARCHAR

tbl_lessons

lessonID
INT

topicID
INT (FK)

Other fields


I have a query that gives me all the topics who's parentID = $whatParentID
:

"SELECT topicID FROM tbl_topics WHERE parentTopicID=$whatTopicID"
Now I want to modify this query so I get a second column called count that
contains the number of times the returned topicID is found in tbl_lessons
even if that count is 0.
Example result:

topicID
Count

1000
2

1003
0

1021
4

In this example, topics 1000,1003,and 1021 all have a parentID of 1009 (or
whatever) and 1000 has 2 lessons, 1003 has 0, and 1021 has 4.
Anyone? Anyone? Bueller? Bueller?

BAD JOKE: (read this outloud)

Have you heard about circus sex? its in tents.


Jul 17 '05 #1
1 1706
On Sun, 21 Mar 2004 02:38:01 GMT, "Alexander Ross"
<al******@bleen.net> wrote:
Lets say I have 2 tables, tbl_topics and tbl_lessons:
tbl_topics

topicID
INT

parentID
INT

Title
VARCHAR

tbl_lessons

lessonID
INT

topicID
INT (FK)

Other fields


I have a query that gives me all the topics who's parentID = $whatParentID
:

"SELECT topicID FROM tbl_topics WHERE parentTopicID=$whatTopicID"
Now I want to modify this query so I get a second column called count that
contains the number of times the returned topicID is found in tbl_lessons
even if that count is 0.
Example result:

topicID
Count

1000
2

1003
0

1021
4

In this example, topics 1000,1003,and 1021 all have a parentID of 1009 (or
whatever) and 1000 has 2 lessons, 1003 has 0, and 1021 has 4.
Anyone? Anyone? Bueller? Bueller?
"
BAD JOKE: (read this outloud)

Have you heard about circus sex? its in tents.


SELECT t.topicID, c.count FROM tbl_topics t inner join (select
topicID, count(1) from tbllessons group by topicID) c on c.topic_id =
t.topic_id WHERE t.parentTopicID=$whatTopicID"


Jul 17 '05 #2

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

Similar topics

7
by: AF | last post by:
I am a real novice to php and MySQL, with about a week's worth of reading and self tutoring. I have an urgent need to publish a database of information and need some guidance on how to do this. ...
16
by: Michael | last post by:
I know how to display random jokes or sayings. But only if I reload the page does the script select a new saying. How can I click on the saying and have it load a new one in its place.
68
by: Ted Nicols | last post by:
That's what I keep asking myself whenever develop in .NET. Is this a joke a farse or just a bad dream? ..NET is slow, actually slow is just a polite word I can use in a newsgroup. ..NET is...
4
by: Matt Horsey | last post by:
There are two men, an Englishmen and an Australian, wearing their respective cricket uniforms, in the men's room. After finishing up, the English man walks to the sink to wash up. The Aussie man...
6
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these...
67
by: Bob Powell | last post by:
To whom it may concern: I find the recent articles in various trade publications a little disturbing due to the lack of PostgrSQL mention. I continue to see articles about how IBM may be...
10
by: Simon | last post by:
Hi, I need to export a 200MB database from one domain to another. phpMyAdmin timeout after a while and is not ideal. I don't mind spending money if I have to but this is rather urgent. I...
0
by: edward_sanders | last post by:
Hi, This is a newbie question. I am using a text for learning php/mysql. I am using PHP 5.2.x and mysql 5. The example is that of a mysql database of jokes. Before we get to joins there is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.