Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL 18 - How to Retrieve a Random Row in SQL PR2 #72

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fed41a2
Create sql-random-mysql.sql
letscodewithsriram Jul 11, 2024
0a8b820
Create sql-random-mssql.sql
letscodewithsriram Jul 11, 2024
746a63b
Merge pull request #3 from letscodewithsriram/letscodewithsriram-patch-8
letscodewithsriram Jul 11, 2024
f8d044b
Create sql-random-postgres.sql
letscodewithsriram Jul 11, 2024
edb365b
Delete sql-queries-2/sql-retrieve-random/sql-random-postgres.sql SEL…
letscodewithsriram Jul 11, 2024
b9431f2
Create sql-random-postgres.sql
letscodewithsriram Jul 11, 2024
13b8780
Create count-over.sql
letscodewithsriram Jul 12, 2024
53f5820
Delete sql-queries-2/sql-get-paginate/count-over.sql
letscodewithsriram Jul 13, 2024
87c23af
Merge branch 'Baeldung:main' into main
letscodewithsriram Aug 12, 2024
90490b9
Merge branch 'Baeldung:main' into main
letscodewithsriram Oct 18, 2024
0e3d1c0
Create escape-quote-mssql.sql
letscodewithsriram Oct 18, 2024
20de4b3
Merge pull request #4 from letscodewithsriram/letscodewithsriram-patc…
letscodewithsriram Oct 18, 2024
1a8e832
Rename escape-quote-mssql.sql to escape-quote-pssql.sql
letscodewithsriram Oct 18, 2024
f2a1bf4
Merge pull request #5 from letscodewithsriram/letscodewithsriram-patc…
letscodewithsriram Oct 18, 2024
43c2086
Create escape-single-quote-mysql.sql
letscodewithsriram Oct 18, 2024
01943ec
Merge pull request #6 from letscodewithsriram/letscodewithsriram-patc…
letscodewithsriram Oct 18, 2024
b1bdf40
Create escape-quote-mssql.sql
letscodewithsriram Oct 18, 2024
34ee2fc
Merge pull request #7 from letscodewithsriram/letscodewithsriram-patc…
letscodewithsriram Oct 18, 2024
28d36f1
Merge branch 'Baeldung:main' into main
letscodewithsriram Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sql-queries-2/sql-retrieve-random/sql-random-mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT TOP 1 *
FROM Faculty
ORDER BY NEWID();
4 changes: 4 additions & 0 deletions sql-queries-2/sql-retrieve-random/sql-random-mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT *
FROM Faculty
ORDER BY RAND()
LIMIT 1;
14 changes: 14 additions & 0 deletions sql-queries-2/sql-retrieve-random/sql-random-postgres.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SELECT *
FROM Faculty
ORDER BY RANDOM()
LIMIT 1;

SELECT *
FROM Faculty
ORDER BY RANDOM()
LIMIT 2;

SELECT *
FROM Faculty
ORDER BY RANDOM()
LIMIT 3;
4 changes: 4 additions & 0 deletions sql-queries-7/escape-single-quote/escape-quote-mssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, 'John O' || CHR(39) ||'Liu', 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);
19 changes: 19 additions & 0 deletions sql-queries-7/escape-single-quote/escape-quote-pssql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, 'John O'Liu', 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);

INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, 'John O''Liu', 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);

INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, $$John O'Liu$$, 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);

INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, 'John O' || CHR(39) ||'Liu', 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO
Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES
(1001, CONCAT('John O', CHAR(39), 'Liu'), 123345566, '2001-04-05', '2020-01-15', '2024-06-15', 4);