Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

better sql syntax

Posted on 2011-09-09
7
Medium Priority
?
252 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 1336 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 664 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
TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

 
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 1336 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

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…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
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…
Suggested Courses

704 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