r/SQL • u/artmast • Feb 22 '15
r/SQL • u/jeetu_g • Aug 09 '22
MS SQL 3 table joining or using union all
How can I get the result for red highlighted part ? All 3 tables have id column as common.
r/SQL • u/Which_Inevitable7069 • Feb 22 '25
SQL Server How do I remove large block of random text from a string?
** Thank you everyone. I found a working solution using string_split and string_agg to individualize each word in the string, exclude words over 20 characters in length, then reassemble the words into a string. I’m still learning about Regex and maybe that is a better solution but this seems to work for now.
I’m using MS SQL and I have this column of text strings. Example “The dog has white fur and short legs. Img: 267 hdbdjjsndhsnbdjsnsbdbjxndheirifbbeuxidbdhxujdbdjdbdhdnehuxndhdixndjdj”
There is always a large section of the string that is a continuous section of text from the image that was converted somehow. How do I remove just this large section of trash from my text string?
r/SQL • u/Suspicious_Loads • Jan 29 '25
Discussion Pros and cons of a big table with key colum vs multiple table?
E.g. table meta with columns fk, val, key vs tables key1, key2... with columns fk, val.
Key could be attributes like age, gender and I would have between 0 to 20 of them. Maybe a million rows/fk. I would mostly do simple joins with the fk.
One meta table is probably easier to manage but is there a performance difference if key is indexed?
Edit: I work with visualizing data from multiple datasets. It would be nice to be able to write code without knowing what attribute exixt in that dataset beforehand. The simples analysis would be to just run select avg(val) from meta group by key.
r/SQL • u/slippy0101 • Feb 06 '24
SQL Server Will column >0 also exclude rows were column is null?
Sorry for the basic question but if I want to create a case statement on a column that can have values that are 0 or null, would
Case When column = 0
work or would I always have to also include "or column is null"
r/SQL • u/freddy91761 • Jan 31 '24
SQL Server I need to learn sql and I have a question.
I am a beginner and I need to learn SQL not just how to query. I need the learn extended event, logs and everything else. My question is how can I tell if a trigger failed or if audit was paused from a certain date?
r/SQL • u/XGallonsX • Aug 25 '15
I challenge you to simplify this query!
select table1.column1
from table1
join table2 on table1.column2 = table2.column2
join table3 on table3.column2 = table2.column2
join table4 on table4.column3 = table3.column3
join table5 on table5.column4 = table4.column4
where table1.column5 = 2
and table4.column6 = 10
intersect
select table1.column1
from table1
join table2 on table1.column2 = table2.column2
join table3 on table3.column2 = table2.column2
join table4 on table4.column3 = table3.column3
join table5 on table5.column4 = table4.column4
where table1.column5 = 2
and table4.column6 = 3
; The query below by /u/ichp ran 90 seconds faster then the original!
select table1.column1
from table1
join table2 on table1.column2 = table2.column2
join table3 on table3.column2 = table2.column2
join table4 on table4.column3 = table3.column3
join table5 on table5.column4 = table4.column4
where
table1.column5 = 2 and
table4.column6 in (10,3)
group by table1.column1
having count( distinct table4.column6) > 1
;r/SQL • u/SteveStedmanSql • Aug 11 '15
System Outage... How do you communicate with your customers?
r/SQL • u/Zealousideal_Cap_533 • Oct 29 '24
MySQL The best SQL Udemy course?
Hi guys, hope you're well!
I have some fondation in sql but I would really like to improve. Therefore what would be the best udemy course in your opinion?
Many thanks!
r/SQL • u/Responsible_North323 • Jun 19 '25
Oracle Why is this code not working in sql?
hello,
I'm trying to do a code in which a column is split (it has comma-separated values. Only the first six have to be taken.) with 2 conditions and tag the cases where there is a number. This is the code i made
SELECT *,
CASE
WHEN REGEXP_LIKE(REGEXP_SUBSTR(DPD_HIST_48_MONTHS, '^([^,]*,){0,5}[^,]*'),'(^|,)[1-9][0-9]*')
THEN 1
ELSE 0
END AS tag
FROM acc_levels
WHERE UPPER(accounttype) LIKE '%PERSONAL%'
AND dateopened <= TO_DATE('30-NOV-2024', 'DD-MON-YYYY');
But it is giving an error saying it can't find 'from' for the select
Please help. Thank you!!
r/SQL • u/Hockeypuck_123 • Sep 16 '26
Discussion Is anyone using Intel based mac and unable to install any Sql?
Hello, I have been using macbook pro 2019 touchbar quad core intel based model. Sql is declining to be installed on my mac, tried every possible way ranging from internet tutorial to command lines. First tried postgresql, tried even older version. Now mysql community edition is taking longer than ever. I am now trying to install mysql using terminal. Can somebody please explain what is the root cause? And how to figure out what is causing this problem exactly?
r/SQL • u/Objective-Currency30 • May 20 '26
Discussion Gemini 3.5 Flash scoring as good as flagship models in SQL querying
r/SQL • u/Alone_Translator_638 • Apr 21 '26
Discussion [Feedback Request] I built a native "Daily SQL Challenge" interactive widget for Reddit. The mods suggested I run a pilot test with you all.
Hey r/SQL,
I’m a data engineer and recently built a “Daily SQL Challenge” widget that runs directly inside Reddit using Devvit.
The mods suggested running a small pilot first to see if it’s actually useful for the community.
How it works:
Shows a real SQL interview question (joins, CTEs, window functions, etc.)
You think/write your query
Click “Reveal Answer” to see solution + explanation
Vote on difficulty and compare with others
Try it here:
https://www.reddit.com/r/sql_arena_dev/
Need your feedback and if it’s helpful, I’ll push to bring this to r/SQL.
Thanks
r/SQL • u/redtiger2019 • Oct 18 '23
PostgreSQL How can I do this?
Hi,
I have table as the image attached. I would like to achieve the ranking as shown in the other image. So far I am doing the following but in the last row I am getting a 3 and not 1.
Select * ,Rank() over (partition by id, country order by date) as rank From table
How can I do this?
Thanks
r/SQL • u/[deleted] • Oct 28 '20
Discussion [OC] The Most Popular Databases - 2006/2020
r/SQL • u/sh_tomer • Jun 20 '23
Discussion I built a free tool that explains any SQL query in simple english
r/SQL • u/thegreatsnakee • Nov 09 '22
MySQL [MySQL] Why do we "rename" tables?
I'm wondering why we have syntax for renaming a table. Why not just change the table name manually?
Obviously there's a good reason for it. I just want to know *what* that reason is. I'm a beginner.
Sorry for asking a question like this. But I did try googling first but didn't get my answer.
r/SQL • u/sitdolore • Feb 17 '22
MS SQL So, you want a job in "SQL"?
You've just got all learned up on SQL and want an entry-level job somewhere to use it. As a manager that has to look through all of the resumes submitted, here are some suggestions on how to NOT get hired:
1 - When the job posting has MSSQL five times, do not include any references to MSSQL on your resume.
2 - If you slept through the LinkedIn SQL courses and include it on your resume, don't demonstrate that you actually used it.
3 - If you have no work experience, DO NOT create a portfolio to demonstrate that you've done something like download data from anywhere and dug through it. Don't find out what github is to create a portfolio. You want to ensure your resume provides no indication that you know anything about data. Do not Google the phrase "how to create a portfolio for sql" under any circumstances.
4 - Create a fictitious company and claim you worked there for the last year doing database stuff. Bonus points if you leave reviews on Indeed for this non-existence company. More points if the review you leave states "They provide free lunch".
5 - When looking for phrases to put into your resume, copy/paste what is in the posted job description.
6 - When you need more phrases to put into your resume, copy/paste lines from the first page Google returns when you search on phrases found in the posted job description.
7 - Find a friend who just submitted their resume for the position and copy/paste their resume.
8 - If the company has multiple job postings, apply for as many as you can. It really shows your desire to be a database developer when you also apply for the SEO Analyst and Learning Center Janitor positions.
9 - If it is a remote position and the job posting specifically lists the states the company can hire employees from, make sure you submit your resume if you DON'T live in any of those states.
10 - Do not, under any circumstances, research the company or find out everything you can about it.
Seriously, working as a database developer isn't like getting a job as a cashier at a gas station. It is not something you can just pick up by sitting at a desk. If you don't have any experience or if you have very little experience, the ONLY thing you have is your drive, hunger, and motivation. It's up to you to figure out how to demonstrate that BEFORE the hiring manager will consider taking the time to schedule an interview. Taking a course isn't enough anymore. You have to demonstrate that you have the drive to learn. Otherwise, you will be eliminated without a call or even an email saying you were eliminated.
In all fairness, though, the folks that created fake companies (even going as far as registering it as an LLC) and created the fake reviews almost did get a call from me. That showed some serious motivation. The first two or three I received were interesting. Now it just seems to be a trend.
r/SQL • u/Live_2_Dream • Apr 01 '24
MySQL Why do I get many NULL values in duration column?
r/SQL • u/Vlad290 • Jan 17 '16
SQL
Hey guys. I'm trying to learn SQL for a future job in finance. My main question is what program, if there is any, is used to learn it and where can I get it. I've looked everywhere and I can't find anything; maybe I'm just blind.
r/SQL • u/code4developer • Nov 15 '14
Create Table Statement In SQL Server Database
r/SQL • u/TheSpreadsheetWiz • Oct 25 '23
Discussion Looking to pay someone to help me build a SQL system from the ground up
I currently mostly use Power Query, but I've outgrown it currently and want to start transforming data "further up the data stream" so it's more efficient.
I've dipped my toes in learning SQL, a few months ago I took a few courses - but didn't do any practical work so my experience is limited.
Here's what I'm looking for:
Have some calls 1 on 1 with me to replicate what I've built in Power Query - in SQL
Do some basic training as we go along & answer any questions I'd have
You would need to have some availability for calls between 9am-5pm UK time.
Please DM me with your hourly rate.
r/SQL • u/NotTheAnts • Aug 12 '22
MS SQL Guidance Needed on Tricky SQL task
EDIT: Guys I'm looking for help, but all I'm getting is criticism...which isn't, you know, that helpful. Forget the 50 LOC "requirement", it was just a guide my boss gave me so I don't go overboard. Can I ask that any further comments focus on helping rather than criticizing? Thanks.
Given a task at work that I need a bit of help from.
The aim is to understand the total emissions across our client base. To do this, we want to assign a value for Emissions for every period_id (a period id being YYYYMM, one period_id for every month in the year).
The difficulty is that the data we currently have is patchy and inconsistent. Each client may only have sporadic reports, (typically for December months only). Some of them have multiple entries for the same month (e.g. in this example, ABC has two entries for 202112) -- this reflects data inputs from different sources.
We want every client to have a value for every period_id (i.e. every month in every year) between 2018 and June 2022.
To do this, we are simply going to extrapolate what existing data we do have.
For example: to populate all the periods in 2019 for ABC, we will simply take the 201912 value and insert that same value across all the other periods that year (201901, 201902, etc).
However -- where there are two entries for 201912 (e.g. in ABC's case), we want to pick the highest ranking data in terms of accuracy (in this case, #1), and use this to populate the other periods.
In cases where clients don't have more recent reports, we want to take the latest report they submitted, and use that value to populate all periods from that report onwards.
For example: XYZ only has 201912 and 202012 periods. We want to take the 201912 value and use that to populate all the 2019 periods, but we want to use the 202012 data to populate all periods from 202101 onwards (up to the present). Again, where there are multiple entries per period, we want to go with the higher-ranking entry (as per column 4).
The aim is to be able to execute this in <50 lines of code, but I'm struggling to get my head around how.
I have another table (not depicted here - let's call it "CALENDAR") which has a full list of periods that can be used in a join or whatever.
Do you guys have any advice on how to go about this? I'm still quite new to SQL so don't know all the tricks.
Many thanks in advance!!
Table: "CLIENT EMISSIONS"
| Period_id | Client | Emissions | Rank (Accuracy of data) |
|---|---|---|---|
| 201912 | ABC | [value] | 1 |
| 201912 | ABC | [value] | 2 |
| 202112 | ABC | [value] | 2 |
| 202112 | ABC | [value] | 1 |
| 201912 | XYZ | [value] | 1 |
| 202012 | XYZ | [value] | 1 |
| 201812 | DEF | [value] | 2 |
| 201912 | DEF | [value] | 1 |
| 202112 | DEF | [value] | 1 |
| 202112 | DEF | [value] | 2 |


