r/SQL • • Apr 13 '19

MS SQL [MS SQL] When to use a CTE vs. a temp table?

33 Upvotes

Title is pretty self-explanatory. I work with some developers that love CTE’s, while I like to break up similar queries into temp tables. I’ve fixed major performance issues in stored procedures by simply turning a CTE into a temp table. Are there any benefits to using a CTE instead of a temp table, besides recursive CTE’s? If it matters, I’m referring to temp tables as the “#” tables, but sometimes I’ll substitute that for a “real” table that I just end up dropping at the end of a procedure. I have never really used “Variable” temp tables, so feel free to add those into the mix of your answer if they respond differently than the other 3 table object types I’ve mentioned.

r/SQL • • Sep 19 '22

MS SQL [MS SQL] SQL Server 2019: simple select * from 3.5 million rows table is taking around 1 minute 35 seconds. How to improve the performance?

14 Upvotes

Hello,

SQL Server 2019: simple select * from the table of 3.5 million rows table is taking around 1 minute 35 seconds. How to improve the performance?

Edit: Thank you everyone for your responses. I'm just testing how much time it will take just to do a simple select *. This table will be used by the majority of other tables in the warehouse. Trying to understand how best we can setup hardware/Index for better performance for future complex queries.

Any tips and techniques to change hardware or index info ?

r/SQL • • Aug 30 '22

MS SQL BEST MS SQL Mastery course in UDEMY or elsewhere

20 Upvotes

I am looking for a serious MS SQL Server coruse and very complete, from zero to advanced stuff. Which is the best course you've ever encountoured in udemy or elsewhere?

r/SQL • • May 03 '22

MS SQL Reoccurring query, no hard coding, MS SQL

1 Upvotes

I am looking for a WHERE clause to set a reoccurring query to be run for the past 2 weeks. No hard coding can be used. Anyone have any ideas?

Have tried “>= getdate() -14 “ and that’s not pulling how I want. Any suggestions help.

r/SQL • • May 14 '22

MS SQL SQL Server - select only the row with the most recent datetime value in a column

7 Upvotes

Hi All

I'm trying to select *only* the row with the most recent value from a table. This is what I have, which I thought was working but turns out not to be:

select [Column A], max([Column B]) alias ,[Column C] from [Table]

where [Column A] = 'some value'

group by [Column A],[Column C]

This seems to work if the rows returned have the same data in Column C, but if the values in Column C differ, multiple rows are returned.

Any idea how I can get *just* the row with the most recent value in Column B? I do need the value of Column C for *that record* to be returned as well.

I should probably add that the above select is actually used in a left join rather than being stand-alone.

Ta

Si

r/SQL • • Feb 23 '22

MS SQL SQL Project Ideas for Data Analysis Portfolio Project

87 Upvotes

Hey Guys! Hope you're doing well.

I'm shifting my career from Mechanical engineering to Analytics/Data science field.

So far I've learned basic to intermediate SQL commands.

Now I want to use those commands and build a portfolio project just to showcase my proficiency in SQL.

Any ideas/recommendations for Portfolio project? Also share some dataset source, if possible

r/SQL • • Jan 31 '22

MS SQL Recommended SQL learning path. From beginner to expert.

41 Upvotes

Hello all.

I want to increase my SQL knowledge and master this.

I am looking for a good learning path that I can follow to master SQL.

As it's a broad subject. I'd prefer to get your top suggestions on what to learn first.

I can do this on my own. But would like to avoid spending too much learning something I may never use.

It would also be cool to learn how someone would first approach a query. So any good blogs would be great.

Much appreciated.

Steven.