Solved

better sql syntax

Posted on 2011-09-09
7
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 334 total points
ID: 36511224
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
ID: 36511258
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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 42

Expert Comment

by:dqmq
ID: 36511424
What indexes do you have on the tables?
0
 

Author Comment

by:amucinobluedot
ID: 36511502
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
ID: 36512077
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
ID: 36512104
Thank you.
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

734 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