what's your SQL resources (beginner)
-
Fresh from Eric Darling[^]. It talks about Joins.
Jack of all trades, master of none, though often times better than master of one.
I’m not going to talk about right outer joins, because that’s the foolish domain of characterless buffoons who use Venn diagrams to explain join results. :laugh: /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
I generally start with W3Schools SQL Tutorial[^] - they explain the basics, and provide DB samples and sandboxes so you can try it yourself without installing the heavyweight monster that is Sql Server. Basically, SQL is a relational DB - it works with multiple tables to relate data to other data, unlike for example CSV which is a flat self contained file where all related data in combined into a single row. So you can have an Invoices table (which holds the invoice date, customer, delivery address, and taxes / total owed) and a InvoiceLines table (which holds the items that were purchased: product, unit price, quantity, discount, Item total, InvoiceID). To look at a whole invoice, you use a JOIN:
SELECT i.InvoiceDate, i.Total, i.PaidStatus, l.Product, l.UP, l.QTY, l.Disc, l.itemTotal
FROM Invoices i
JOIN InvoiceLines l ON l.InvoiceID = i.ID
WHERE i.ID = 123456The InvoiceID relates the two bits of information and returns only the relevant data.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
I used get daily quizzes from SQLServerCentral – The #1 SQL Server community[^] and learned a lot from them. I've been writing SQL queries my entire career (25 years) and learn something new all the time. Good luck! :) FWIW, especially for a beginner, the query designer in Access is easier to work with than the query designer in SSMS. Just my 2 cents, I'm sure I'll catch hell for this comment. :-D ;P
"Go forth into the source" - Neal Morse "Hope is contagious"
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
I find books with "Recipes" in the title useful; as in: "SQL Cookbook". The "Q&A" format (by "category") is the least time wasting when looking for a solution or insight into one.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
I use my own articles: Querying SQL Server 2012: Part I[^] Querying SQL Server 2012: Part II[^] It's starts with the basics, explaining SELECT ... FROM ... and then goes into WHERE, JOIN, GROUP BY, etc. I use it when I need something more exotic, like a grouping set, windowing function or pivot.
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
I'm not a database person myself, so I was probably in the same situation as you when it came to figuring out joins and stuff. I ended up creating a mental image that I found useful. For what it's worth, here it is: JOIN = add columns of table B to the columns of table A getting a wider table. columns used in join = imagine column from table A as "red" data and column from table B as "green" data Arrange rows in table to have first those where both red and green data are equal. Continue with remaining rows in table A (only red data, green data is empty). Finish with remaining rows in table B (only green data). Now: - INNER JOIN = take only the first part where red and green are equal - LEFT JOIN = take first two parts (the equal and other red rows) - RIGHT JOIN = take first and 3rd parts (the equal and green rows) - OUTER JOIN = take all. Just my 0.02$
Mircea
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
My resources (which I suspect many, many database developers or software engineers that also develop T-SQL do in some form or fashion) are: * Brain - by understanding and visualizing what the data design and queries/statements are doing helps eliminate a lot of bad ideas and wasted time. * SSMS - still the most comprehensive and easiest to use, IMHO, though sometimes I use the DB tools in Visual Studio. * SQL Server - I've tried others, but the support costs for multiple DB providers in the latter part of the SDLC for the customer are higher (in almost all use cases) that just using SQL Server correctly for the task at hand. * Consistency - solving the same problem with the same design, unless a newer design is demonstrably better in terms of execution, resources, and supportability. * CRUD - I limit my use of SQL Server (or any DB server) to CRUD (or in more common SQL terms, SELECT, INSERT, UPDATE, and DELETE) and leave the business logic to the C# code executing on the server or in the cloud app service. Database servers are designed to optimize reading and writing of data, not running business logic because it is easier to "just stick it all in the SQL".
-
I generally start with W3Schools SQL Tutorial[^] - they explain the basics, and provide DB samples and sandboxes so you can try it yourself without installing the heavyweight monster that is Sql Server. Basically, SQL is a relational DB - it works with multiple tables to relate data to other data, unlike for example CSV which is a flat self contained file where all related data in combined into a single row. So you can have an Invoices table (which holds the invoice date, customer, delivery address, and taxes / total owed) and a InvoiceLines table (which holds the items that were purchased: product, unit price, quantity, discount, Item total, InvoiceID). To look at a whole invoice, you use a JOIN:
SELECT i.InvoiceDate, i.Total, i.PaidStatus, l.Product, l.UP, l.QTY, l.Disc, l.itemTotal
FROM Invoices i
JOIN InvoiceLines l ON l.InvoiceID = i.ID
WHERE i.ID = 123456The InvoiceID relates the two bits of information and returns only the relevant data.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
I would second W3Schools! It has very helpful learning tools that I still rely on at times when I am trying to remember how to do something...
Steve Naidamast Sr. Software Engineer Black Falcon Software, Inc. blackfalconsoftware@outlook.com
-
I used get daily quizzes from SQLServerCentral – The #1 SQL Server community[^] and learned a lot from them. I've been writing SQL queries my entire career (25 years) and learn something new all the time. Good luck! :) FWIW, especially for a beginner, the query designer in Access is easier to work with than the query designer in SSMS. Just my 2 cents, I'm sure I'll catch hell for this comment. :-D ;P
"Go forth into the source" - Neal Morse "Hope is contagious"
I was trying to work up the courage to suggest MS Access - fearing that same heck. Bring your data, or let it build a template application for you. Visually design your query, then change to the SQL view and figure out what it is doing. You can write SQL that the visual designer cannot present (eg. sub-select). You cannot write all SQL (eg. cartesian join). Whilst you may not want to deploy it as an application (I have), it works to model or proof-of-concept for a business app. b
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
"
what's your SQL resources
Brent Ozar.
-
So, what's your SQL resources for beginners and related to JOINs ? I'm kind of stuck on request that should use JOIN and can't figure out how to make it work. I somewhat understand how it works, but there's something missing in my understanding of the universe. Thanks.
CI/CD = Continuous Impediment/Continuous Despair
If you're familiar with how joins work but are having problems figuring out how to use them in a particular query, it might be good to back up and look at the structure of the database you're working with. For instance, do you even have a good key to join on? A poor DB structure with a lack of normalization can make joins difficult or even impossible. If that's the problem, one way around it is to throw the data into temp tables with the correct structure you need for the joins and query against that. Speaking of which, in a addition to learning about SQL it's also a very good idea to learn the fundamentals of database design if you haven't already. Knowing about things like normalization, keys, and indexing really helps when writing SQL.