Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Ezilon Directory   High Bandwidth Dedicated Servers   V7N Directory

Reply
 
LinkBack Thread Tools Display Modes
Old 10-12-2004, 09:54 PM   #1 (permalink)
v7n Mentor
 
Sketch's Avatar
 
Join Date: 05-06-04
Location: London, UK
Posts: 1,452
iTrader: 0 / 0%
Latest Blog:
None

Sketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web pro
SQL Query

Hi, I have a problem with my SQL Query

Code:
SELECT A_ID, A_TITLE, COUNT( B_ID ) FROM ComBoard, msBoard WHERE A_ID = B_ID GROUP BY A_ID
Its very simple. Its counting how many B_ID's = A_ID. But my problem is, if the count = 0 it will not show up.

For example;
I have;
A_ID = 1
A_ID = 2
A_ID = 3

And

B_ID = 2
B_ID = 3

My query will return

A_ID: 2 & 3

But not A_ID 1.

I hope that makes sence.

If some one could give me a hand that would be great.

Thank You
Sketch is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 10-13-2004, 07:13 AM   #2 (permalink)
Inactive
 
littleFella's Avatar
 
Join Date: 06-20-04
Location: Ontario
Posts: 3,359
iTrader: 0 / 0%
Latest Blog:
None

littleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to beholdlittleFella is a splendid one to behold
Code:
SELECT A_ID, A_TITLE, COUNT( B_ID ) FROM ComBoard, msBoard WHERE A_ID = B_ID GROUP BY A_ID
You used INNER JOIN which will return only thiose record for which there are matches in both tables.

You should use LEFT or RIGHT JOIN, depending which table lacks the matching records.

PHP Code:
SELECT A_IDA_TITLECOUNTB_ID 
FROM ComBoardmsBoard
[b]LEFT[/bJOIN second_table
ON ComBoard
.A_ID ComBoard.B_ID
GROUP BY ComBoard
.A_ID

or

SELECT A_IDA_TITLECOUNTB_ID 
FROM ComBoardmsBoard
[b]RIGHT[/bJOIN second_table
ON ComBoard
.A_ID ComBoard.B_ID
GROUP BY ComBoard
.A_ID 
littleFella is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-13-2004, 03:48 PM   #3 (permalink)
v7n Mentor
 
Sketch's Avatar
 
Join Date: 05-06-04
Location: London, UK
Posts: 1,452
iTrader: 0 / 0%
Latest Blog:
None

Sketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web proSketch is a highly respected web pro
Gosh, I feel so stupid that I didn't even think of that.

Thank You so much I was stuck on it and I had no idea what to do.

I had to change the code a little, but it works great now.


Cheers Again!
Sketch is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql Query itHighway Web Design Lobby 1 03-17-2008 12:09 PM
SQL Query Sketch Coding Forum 9 12-13-2006 12:26 PM
Problems with a query onlinegamenet Coding Forum 1 04-11-2005 09:22 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 12:01 AM.
© Copyright 2008 V7 Inc