r/learnSQL

Newbie Learning SQL

Hi , I am a newbie learning SQL. Just wanted to say hi here ! Can i ask questions and ask for help with code here ? Thanks

reddit.com
u/CaiGY — 4 days ago

Day 32 + 33 / 116 — Combined day: 15 Hard JOIN questions in one sitting (85/100)

Sorry guys, I missed Day 32, so to make up for it, I combined both days’ work on Day 33.
I spent the entire day solving SQL questions, pushing myself to the hard level.

I did 15 Hard-level questions from my 100-question JOIN lab, and they’re clearly harder than the Medium ones. Some highlights:

  • Departments that have at least one employee earning more than every employee in Sales, solved with GROUP BY dept_id and HAVING MAX(salary) > (SELECT MAX(salary) ... WHERE dept_id = 2)
  • Flagging each employee as “Above Average” or “Below or Equal” using a CASE expression against the company average
  • A department report with employee count, project count, and total combined project budget. My first attempt used UNION ALL and threw Error 1222 (different number of columns). The fix was to aggregate employees and projects separately in subqueries, then join them on dept_id

That last one taught me the most. Employees and projects are two different one-to-many relationships, so joining them directly would multiply the counts. Aggregating each side first is the safer pattern.

15 questions left. Any tips for “compared to every/all” style queries are welcome.

reddit.com
u/sumiitCodes — 5 days ago
▲ 1 r/learnSQL+1 crossposts

How to move the responsibility of executing some logic to the Sql Server instead of executing that logic inside the application?

I have Excel file that contains many columns like this :

SKU BarCode EnglishName ArabicName Category SubCategory

There are other columns, but there is no need to show them to convey the problem behind this post. The Excel file is sent from the client to the server which will read it using C# .

The problem : The data of the above Excel file should be persisted to the appropriate tables in the Sql Server database which does not merely contain a single table, so, a specific data from the Excel file should be consumed by a specific table in the database, the problem is not simple as send the data of the Excel file to only one destination table; the source is only one, which is the Excel file, but there are many destination tables. Database contains parent and child tables; parent tables do not contain foreign keys, child tables contain one or more foreign keys. The data for the child tables cannot be persisted to the database unless the data for the parent tables is persisted first.

I have the following C# domain classes/models:

public interface IEntity{

}

public  interface IParent:IEntity{

}

public interface IChild : IEntity{


}
public interface INonJunctionChild:IChild{

}

public interface IJunctionChild:IChild{

}

public class Product:IParent
{
    public string? SKU { get; set; }     // SKU column in Excel
    public  string? Barcode{ get; set; } // BarCode column in Excel
    public string? EnglishName {get;set;} // EnglishName column in in Excel
    public string? ArabicName { get; set; } // ArabicName column in Excel
    public IEnumerable<ProductCategory> ProductCategories { get; } = new List<ProductCategory>();  
    
    // Alot of other navigaton properties.....

}

public class Category:IParent{
  public string EnglishName {get;set;} // Category column in Excel
  public IEnumerable<ProductCategory> ProductCategories { get; } = new List<ProductCategory>();
  public IEnumerable<SubCategory> SubCategories { get; }=new List<SubCategory>();    


  // alot of other  navigation properties....
}

public class SubCategory:IChild{
  public string EnglishName {get;set;} // SubCategory column in Excel
  public string CategoryId {get;set;} // Foreign key; populated using lookup operation.
   
}
public ProductCategory{
  public int ProductID {get;set;} Foreign key; populated using lookup operation.
  public int CategoryId {get;set;} Foreign key; populated using lookup operation.
  public Product Product { get; set; } = null!;
  public Category Category { get; set; } = null!;
}

My old approach to solve the problem -which worked, but I want to change it- has the following steps:

1-Read the whole excel sheet into the application.

2- Inside the application, populate the specific properties of each parent domain model by assigning specific Excel column values to to them.

3-persist the parent models to the database.

4- Populate the child tables using lookup operations.

5- Persist the child tables to the database.

Instead of the above, I would like to know if the following is possible:

1- Get `DbDataReader` using `Sylvan.Data.Excel and pass it to `SqlBulkCopy` class.

2- The Whole Excel file will be persisted into a staging table or view, and then some trigger will be fired, as a result, some stored procedure or function will be executed, the responsibility of that function or procedure is to persist the data of the parent tables first, then to persist the data of the child tables, which means.

So, In the old approach, can the responsibility for transforming the Excel data, resolving the required relationships, and persisting the parent and child records (steps 2 through 5) be moved from the application layer to SQL Server?

u/kaatarina_zed_talon — 12 days ago

For people who learned SQL from tutorials: how did you handle your first vague stakeholder request? I made a free simulator for it

When I started, the hardest part wasn't SQL syntax. It was translating things like "can you pull repeat buyers by region?" into the right joins, filters and edge cases (cancelled orders, date ranges, duplicates).

I made a free simulator that recreates that: stakeholder emails, real schemas, a PostgreSQL sandbox, and levels that go from a tiny startup to a global corp. Demo video is attached.

I'd love to hear how you practiced this skill, and whether something like this would have helped you. Link in the comments if anyone wants to try it.

reddit.com
u/Gokul_00 — 12 days ago

Do I need to master Stored procedures, Triggers and Indexes or can I use the ui to make them

I'm learning on sql server but I don't like those 3 topics

I learned everything except those 3 topics??

What are the best books to read If I want to be acceptable in those 3 topics?

reddit.com
u/Bassiette03 — 12 days ago
▲ 3 r/learnSQL+1 crossposts

Meta Scaled Business Growth – Recruiter Screen & Interview Process?

Hi everyone,
I was recently contacted by a Meta recruiter regarding a **Scaled Business Growth** position within the **Scaled Business Marketing (SBM)** org and have an initial 30-minute recruiter call scheduled.
The recruiter described it as a highly analytical growth role focused on driving adoption and long-term value across Meta’s business audiences, with a strong emphasis on **SQL, experimentation, opportunity sizing, and scaling data-driven programs across customer segments**.
Would really appreciate hearing from anyone who has interviewed for this role/team or a similar Meta growth marketing position:
What should I expect in the initial recruiter screen, and what should I make sure to address?
What are the typical next steps after the recruiter call?
Is there a **technical/SQL round**? If so, how advanced is the SQL and is it live coding?
What do the **experimentation and opportunity-sizing cases** look like?
Is Scaled Business Growth primarily focused on **advertisers/Meta Ads and SMBs**, or does the team work across other Meta business products as well?
How is the final interview loop structured (analytics, growth case, cross-functional, behavioral, etc.)?
Any specific resources or topics you found useful for preparing?
If anyone has recently interviewed with **Scaled Business Growth, Scaled Business Marketing, Growth Marketing, or a closely related Meta team**, I’d really appreciate hearing about your experience.
Thanks!

reddit.com
u/Relevant-Ask7680 — 11 days ago