Solved

better sql syntax

Posted on 2011-09-09
7
244 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
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
 

Author Comment

by:amucinobluedot
ID: 36511285
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New and Previous Values in a Query 7 30
SQL Query 26 68
CSV How to add columns based on existing column(s)? 20 32
Update one table with results from another table in SQL 6 24
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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