crazy query

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

crazy query

Post by magicrobotmonkey »

Ok here is where I'm at. I have two tables, replies and jobs. I want a query that gets all the replies where the replytext equals one and I also want to get all the jobs. I'm not too familiar with SQLs conditional statements so I'm having some problems with this one. I'm trying something like

SELECT If RText = 1 THEN SUM(RText), COUNT(ReplyID), FROM...GROUP BY JobID

Obviously this is working. Is what I'm trying to do even possible?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Might be, can you post the relevant tables and fields?
User avatar
AnarKy
Forum Contributor
Posts: 119
Joined: Tue Nov 02, 2004 1:49 am
Location: South Africa

Try

Post by AnarKy »

Are these Tables Related?

If not, then you may select them in different queries,
If they are then you can select all of them,
and check those you want, in your actual script.

Im not really sure what your problem is,
but perhaps this will help.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

if anyone else has this question, i did it like this

Code: Select all

SELECT COUNT(IF(RText = 1,1,NULL)),COUNT(JReplyID) FROM Replies, Jobs Where Replies. JobID = Jobs.JobID GROUP BY Jobs.JobID
This gave me a total count of replies for each job alaong with a count of replies where the text was 1

then I foound out none of it mattered anyways...
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

My sympathies. :cry:

Nice query anyway! :wink:
Post Reply