Current location: Hot Scripts Forums » Programming Languages » Other Languages » Sql = help


Sql = help

Reply
  #1 (permalink)  
Old 10-05-11, 12:57 AM
mrstevey mrstevey is offline
New Member
 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Sql = help

hi guys.. first time poster... long time leecher!

this sql query has me beat...

Code:
SELECT runner_mr.RunnerName AS Starts, 
	result_mr.`1st` AS Wins,
	runner_mr.Scratched AS Scratchings
FROM result_mr RIGHT OUTER JOIN runner_mr ON result_mr.`1st` = runner_mr.RunnerName AND runner_mr.MtgId = result_mr.MtgId
WHERE runner_mr.RunnerName = "TESTASCANA"
i would ultimately like to ...

COUNT(runner_mr.RunnerName) AS Starts,
COUNT(result_mr.`1st`) AS Wins,
COUNT(runner_mr.Scratched) AS Scratchings [where scratched = "Y"]

can i do a WHERE clause in the SELECT???
Reply With Quote
  #2 (permalink)  
Old 11-25-11, 02:21 AM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
no you cnat have where in your select. the whole point of the query is that you tell it what to select and from where and what are the conditions. its pretty logical-if your scratched=y in a few of the records what should the sql do with the others? If that has to be a single query you have a few options really:
union(that usually takes a lot of time to process)
or use joins-you can join a table on itself. depending on your case it would be left join or right join. personally ive never had to use right join and to be honest i dont think i know anyone that ever has. here is a decent guide on what they are and what are the differences:
Difference between left join and right join | PHP F(n)
Reply With Quote
Reply

Bookmarks

« Encrypt my website | - »

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Data from Database to Excel via SQL Command and Customize Style of it For VB.NET without Auto tomason Windows .NET Programming 2 08-10-11 03:11 AM
OOP C-Sharp DB Access Wrapper Question digioz ASP.NET 1 09-08-08 09:54 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 10:22 AM
ASP Calendar..HELP...pls jimthepict ASP 1 07-31-03 05:01 PM
change my field in this example sal21 ASP 3 07-14-03 02:49 AM


All times are GMT -5. The time now is 03:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.