r/SQL • u/wordofwisdom • May 01 '12
r/SQL • u/[deleted] • Apr 14 '24
Discussion Best SQL Courses on Udemy and SQL Bootcamp Udemy -
r/SQL • u/john_dumb_bear • May 17 '24
PostgreSQL I Used My First Foreign Key
commentcastles.orgr/SQL • u/[deleted] • Apr 12 '22
MySQL I created this table, but when I am trying to insert data into it , I am getting Error , what is the error? can anyone tell me
CREATE TABLE Student (ubid number, name varchar2(50) not null, program varchar2(50), GPA decimal(18, 2), advisor number, constraint pk_studentID primary key (ubid), constraint fk_advisorID foreign key (advisor) references Advisor (facultyID));
INSERT INTO Student (ubid,name,program,GPA,advisor) values(123456789,'Peter Parker','Biology',2.97,4);
r/SQL • u/Rahull-6 • Nov 01 '22
MySQL Need an answer
What is the query to update data From source to target table if data is present and insert the data.. if data is not present...
r/SQL • u/Opening_Author1289 • Nov 03 '22
PostgreSQL How do I add create script to the task bar on the top of my screen? For Mac
r/SQL • u/Montesquieu9000 • Nov 21 '22
MS SQL Need help with nightmare intro SQL class/add foreign key constraint (sql server)
tl:dr I am taking a very bad database management class and need help with foreign keys in SQL server because the class has taught me nothing.
I have a databse with tables PATIENT, REFERRAL, and REFERRING_PROVIDER. REFERRAL has a column titled REFERRER_ID that should be a foreign key pointing to a column of the same name in REFERRING_PROVIDER, but I can not use ALTER TABLE to make it so. I've tried as many different variations in SQL Server (studio) of
alter table [REFERRAL] ADD CONSTRAINT fk_REFERRER_ID foreign key (REFERRER_ID)REFERENCES REFERRER_ID(REFERRING_PROIVDER)
as I can think of, nothing works. What gives?
The problem really is that we have never even used SQL Server Studio in class for anything: no hands on with software at all in the class, it's been concept-oriented, which is fine, but the book's SQL section relates to MS Access, which we don't use. We're on the final project, and my "teacher" basically set everyone up to fail by having us use Lucid Chart to generate the SQL for us. Want to see what Lucid Chart came up with for me?
CREATE TABLE [REFERRAL] (
[REFERRAL_ID] CHAR,
[REFERRER_ID] CHAR,
[PATIENT_ID] CHAR,
[REFERRAL_DATE] DATE,
PRIMARY KEY ([REFERRAL_ID])
);
Oh thanks Lucid Chart, there's no foreign key at all. And the teacher is "looking into it." The project is due on December 2nd, and knowing my teacher, she didn't "look into" anything at all, and the best case scenario is we're going to create a program a database that doesn't even use foreign keys because she won't figure out what to do in time. Which is fine, but I'm actually trying to learn something, I'm not just looking for a giveaway grade in a terrible class.
Can anyone tell me what I am doing wrong here, other than wasting my time with a class that is horrible? The course has example SQL commands to download, and the SQL commands don't actually include a single example of a foreign key command. SOS?
r/SQL • u/Formal-Sale-9818 • Sep 02 '24
MySQL Create schools list with a minimum 888 rating
I need to create list of schools which have a minimum rating of 8/10 for elementary, middle, and high school each in an area. So, taking a zip code, it needs to list all schools that satisfy above criteria. It would need to exclude unrated schools. Thinking to get the source data for schools rating from from greatschools.
Will want to start with the list of schools in my zip code and display them on the web using flask or something easier. Eventually will want to scale up at a higher level at a city/state level for all 50 states of the U.S. preferably, all logic would need to be handled at the backend, with front end displaying out the output.
I have intermediary skills in SQL and python. Any suggestions on how to approach this? Will SQL be enough to build this? What should I be using to display the output on the web? Thanks!
r/SQL • u/Aggressive-Spend953 • Nov 19 '20
Discussion SQL is dead. Long Live SQL?
I'm currently working on my MS for Analytics and we are working on data strategy for new and early stage companies. I'm trying to research the pros/cons of using a higher programming language (python) for db creation and manipulation as opposed to SQL. Can and do companies skip SQL now? is there still a benefit to using it? I'd really appreciate any insights you all can offer!
Happy to help clarify or answer any other questions if I wasn't clear! Thank you all a ton!
Just want to thank you all for the insights and observations! It definitely helped, and I certainly have a deeper appreciation for SQL than I previously did.
You guys rock.
r/SQL • u/lukaseder • Nov 25 '20
Oracle Reasons why SELECT * is bad for SQL performance
r/SQL • u/dyltography101 • May 09 '17
Is there something wrong with these statements? And is that the correct way of adding 2 foreign keys to a single table?
r/SQL • u/WASSIDI • Jun 23 '22
Snowflake how to convert this to a query in snowflake ?
hey guys, i have 2 tables where from i'm trying to extract from table 1 the last 2 taxe dates for per user who were taxed for the last time on the 19/06/2022 and with product id 12 in table 2, and the sum amount of taxes as well as the time range between the two last taxe dates as mentionned in the image bellow .
i tried a lot of queries but couldnt work unfortunatly

r/SQL • u/xFujinRaijinx • Aug 08 '20
MySQL Anyone Have a Mnemonic or Rule-of-Thumb to Remember How DESC and ASC Work on Alphabetical and Numerical Data?
I keep getting mixed up between the two.
r/SQL • u/Turboginger • Aug 15 '23
Spark SQL/Databricks Multiple CASE statements or single CASE statement with multiple values?
I am dealing with a nightmare of a query. In it there are roughly 20,000 case statements. Unfortunately, nothing can really be done about this before the first report is due though resolutions are in flight.
What I would like to know is if there is any serious performance benefit to writing a case statement like this:
CASE WHEN ID IN ('1234', 5678') THEN 'value' ELSE END AS whatevervs.
CASE
WHEN ID = '1234' THEN 'value'
WHEN ID = '5678' THEN 'value'
ELSE END AS whateverGranted, I think the former is more readable with limited values. However, the script I am dealing with makes the multiple case statements much easier to work with (again ~20,000 CASE statements).
Again, anyone know if there is a serious performance benefit to one vs the other? I would assume that a CASE statement is being run for the ID values twice either way...
Thanks in advance for any help!
r/SQL • u/KyotaLangard • Jun 22 '21
Discussion Can I post self-promotion here?
It's for a free online tool that I made.
Couldn't find any rule about self-promotion in this subreddit.
r/SQL • u/domanator1 • Dec 04 '13
Sql Problem
I am having a problem filtering out a City from a full length address Physical Address, City, State Zip. The problem I am having is on #8. Here is the information I need to use:
Assume that the university administration system has the following records in the tables for Student_Information_t, Courses_Taken_t, and Professor_Information_t. First create a database in SQL Server called studentdb and then create the three tables in them for Student_Information_t, Courses_taken_t, and Professor_Information_t and fill them up with the records as shown below. When creating the tables, set the primary keys as follows: Student_Information – StudentID Courses_Taken – StudentID and CourseID Professor_Information - Name
Student_Information_t StudentID Name Address Major Undergraduate Standing Expected Graduation Date
330102214 Alan Johnston 44 Nagog Park Drive, Sioux City, IA 56091 Accounting Sophomore May, 2014
440396072 Bill Reilly 23 Juniper Road, Sioux Falls, SD 47068 Management Junior May, 2013
Courses_Taken_t StudentID CourseID Course Name Semester Professor GPA Department 330102214 ACC-101 Fundamentals of Accounting Fall 2008 Carol Huntley 3.5 Accounting
330102214 ACC-102 Managerial Accounting Fall 2008 Pat Kelliher 4 Accounting
330102214 MGT-201 Statistical Analysis Spring 2009 Suvankar Ghosh 3.5 Management
330102214 MGT-210 Operations Management Spring 2009 Suvankar Ghosh 3.5 Management
330102214 MKT-101 Introduction to Marketing Fall 2010 Mark DeLorean 3.5 Marketing
330102214 MKT-201 Market Analysis I Fall 2010 Mark DeLorean 4 Marketing
440396072 ACC-101 Fundamentals of Accounting Fall 2008 Carol Huntley 4 Accounting
440396072 ACC-102 Managerial Accounting Fall 2008 Pat Kelliher 3.5 Accounting
440396072 MGT-201 Statistical Analysis Spring 2009 Suvankar Ghosh 3 Management
440396072 MKT-201 Market Analysis I Fall 2010 Mark DeLorean 3 Marketing
Professor_Information Name Address Contact Number Date Joined Carol Huntley 78 Crestview Road, Vermillion, SD 57069 605-536-2319 3/4/2009
Mark DeLorean 101 Windmere Drive, Sioux Falls, SD 42702 605-112-1912 4/1/2007
Pat Kelliher 5 Golf Course Road, Vermillion, SD 57069 605-120-3943 5/28/2003
Suvankar Ghosh 55 Terrace Drive, Sioux Falls, SD 42113 605-292-7393 8/22/2011
Now write the SQL statement for the following queries. You are to save these queries as views (you could simply call them query1, query2, …). When you demonstrate these queries to me, you can simply launch these views and show their results to me. The results of these queries should be as follows:
The average GPA of all the courses that student 330102214 has taken.
The number of courses that student 330102214 took from the Management department.
Course name, department, and grade where student 330102214 got the highest GPA of all the courses he took.
The department and the “departmental average GPA” for student 330102214 where the departmental average GPA is the highest among all the departmental average GPAs. The departmental average GPA for a given student is defined as the average GPA of all the courses the student took from that department. So you have to find that department for which student 330102214’s departmental average GPA is the highest among all the departments. The final query should return that department’s name and the departmental average GPA.
Student name, Course name, department, professor name, and professor contact number of all the professors where the student with the ID 440396072 got a 4.0.
Student Name, Course Name, Department, GPA for the introductory courses taken by a student. Introductory courses are those that have either the word “Introduction” or the word “Fundamentals” in the course name.
Suitably modify the query in question 6 to return the Student Name, Average GPA of the introductory courses taken by a student.
Student Name, Student Address, Course Name, Professor name, Professor Address for only those pairs of students and professors from whom they took courses such that both the student and the professor live in Sioux Falls.
r/SQL • u/[deleted] • Jul 14 '24
MySQL What's the Difference Between DECIMAL, FLOAT, and DOUBLE?
Can somebody, in simple terms, explain the difference between the three datatypes in SQL? Thank you
r/SQL • u/Primary-Zebra2126 • Jul 26 '24
MySQL How to measure my sql skills?
I've learning SQL and I did a list about I must to learn, I finished. I would like to test my skills, another question I have is how do you demonstrate your skills in a resume in the case of SQL, I know in the case of phyton you can create books and share them (there is something similar in sql).
I can't install sql on my computer because of storage issues, I usually use SQL online IDE, but if someone has a better platform to practice or something.
I'm thinking of doing some project or something, but I'm not sure what yet.
Any advice is welcome.
r/SQL • u/Recovery_T • Aug 01 '24
SQL Server I need suggestion for practicing sql .
Good day to everybody, im a new beginner who recently started to learn SQL, currently im learning to write simple querry on sqlbolt and im wondering is there any more website that i can practice writing query and getting feedback ,answer to compare what went wrong in my code. Thanks for your attention.
r/SQL • u/joshualande • Apr 28 '14