Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

better sql syntax

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
Aleks
Asked:
Aleks
  • 3
  • 2
  • 2
3 Solutions
 
lluddenCommented:
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
 
dqmqCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dqmqCommented:
What indexes do you have on the tables?
0
 
AleksAuthor Commented:
I have the attached, I am not too familiar with indexes and if more should be created or not.  screenshot of index
0
 
lluddenCommented:
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
 
AleksAuthor Commented:
Thank you.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now