Solved

better sql syntax

Posted on 2011-09-09
7
241 Views
Last Modified: 2012-05-12
I have the following query, can we make it better?  Please refer to my prev posting as example, that worked real nice.

--

SELECT activities.activityid, activities.ActName, activities.actdesc,activities.dateinitiated,activities.lastmodified,activities.processtep,activities.Partylist
FROM ((dbo.Activities LEFT JOIN dbo.Cases ON dbo.Activities.CaseId = dbo.Cases.Id) )  
LEFT JOIN dbo.Atts ON dbo.Atts.CaseId = dbo.Cases.Id  
INNER JOIN Users ON Activities.sent_by = Users.UserId
WHERE Activities.FirmId = 2   AND  (Activities.ActType = 'Calendar')   AND sent_by = 1713

---

Aleks
0
Comment
Question by:amucinobluedot
  • 3
  • 2
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 334 total points
Comment Utility
That looks like it is the same query as

SELECT A.activityid, A.ActName, A.actdesc, A.dateinitiated, A.lastmodified, A.processtep, A.Partylist
FROM dbo.Activities A
      INNER JOIN Users u ON A.sent_by = u.UserId
WHERE A.FirmId = 2
      AND A.ActType = 'Calendar'
      AND A.sent_by = 1713

The two tables with the left join don't appear to be used at all
0
 
LVL 42

Assisted Solution

by:dqmq
dqmq earned 166 total points
Comment Utility
What do you mean: "make it better"?

You can clean it up cosmetically, for example, eliminate unnecessary parens.  If it's producing the correct results, then what's the issue?  If not, please describe what you want it to do differently.

p.s.  when referencing a previous question, please provide a link to it.

   
0
 

Author Comment

by:amucinobluedot
Comment Utility
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 42

Expert Comment

by:dqmq
Comment Utility
What indexes do you have on the tables?
0
 

Author Comment

by:amucinobluedot
Comment Utility
I have the attached, I am not too familiar with indexes and if more should be created or not.  screenshot of index
0
 
LVL 18

Assisted Solution

by:lludden
lludden earned 334 total points
Comment Utility
If you add indexes on the fields you have in your WHERE clause, that will help.  Some will help more than others based on the frequency of the values in that index.

Adding indexes makes select queries run faster, but slows down insert and update queries.  
0
 

Author Comment

by:amucinobluedot
Comment Utility
Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now