Demo: Query Language Cheatsheet Generation using ChatGPT 3.5

All,

ChatGPT 3.5 is less capable that 4.0, but much faster. Here’s a 
transcript demonstrating the creation of SQL and SPARQL cheatsheets – 
that I just generated (whimsically).


  Transcript

Q: Make a simple SQL Cheatsheet.
Q: Redo, but using a Table for enhanced presentation.
Q: Redo the SQL cheatsheet using a Markdown Table in a code-block.
A:
Sure, here is the SQL cheatsheet presented in a markdown table inside a 
code block:

Command  Description
SELECT  Retrieves data from one or more tables
|SELECT column1, column2, ... FROM table_name;|  
DISTINCT  Retrieves unique values
|SELECT DISTINCT column_name FROM table_name;|  
WHERE  Filters records based on a condition
|SELECT column1, column2, ... FROM table_name WHERE condition;|  
AND/OR  Combines multiple conditions
|SELECT column1, column2, ... FROM table_name WHERE condition1 AND/OR 
condition2;|  
ORDER BY  Sorts the result set
|SELECT column1, column2, ... FROM table_name ORDER BY column_name 
ASC/DESC;|  
LIMIT  Limits the number of results returned
|SELECT column1, column2, ... FROM table_name LIMIT number_of_rows;|  
JOIN  Combines rows from two or more tables based on a related column 
between them
|SELECT column1, column2, ... FROM table1 JOIN table2 ON 
table1.column_name = table2.column_name;|  
GROUP BY  Groups rows based on a column
|SELECT column1, COUNT(column2) FROM table_name GROUP BY column1;|  
HAVING  Filters groups based on a condition
|SELECT column1, COUNT(column2) FROM table_name GROUP BY column1 HAVING 
COUNT(column2) > value;|  
INSERT INTO  Inserts new records into a table
|INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, 
...);|  
UPDATE  Modifies existing records in a table
|UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE 
condition;|  
DELETE FROM  Deletes records from a table
|DELETE FROM table_name WHERE condition;|  

I hope this presentation is helpful and easy to read.

Q: Redo, with an examples column using Northwind
A:
Sure, here is an updated SQL cheatsheet presented in a markdown table 
inside a code block with an additional column for actual usage examples 
based on the Northwind database schema:

Command  Description  Example
SELECT  Retrieves data from one or more tables  |SELECT ProductName, 
UnitPrice FROM Products;|
DISTINCT  Retrieves unique values  |SELECT DISTINCT CategoryID FROM 
Products;|
WHERE  Filters records based on a condition  |SELECT ProductName, 
UnitPrice FROM Products WHERE UnitPrice > 20;|
AND/OR  Combines multiple conditions  |SELECT ProductName, UnitPrice 
FROM Products WHERE CategoryID = 1 AND Discontinued = 0;|
ORDER BY  Sorts the result set  |SELECT ProductName, UnitPrice FROM 
Products ORDER BY UnitPrice DESC;|
LIMIT  Limits the number of results returned  |SELECT ProductName, 
UnitPrice FROM Products LIMIT 10;|
JOIN  Combines rows from two or more tables based on a related column 
between them  |SELECT Products.ProductName, Suppliers.CompanyName FROM 
Products JOIN Suppliers ON Products.SupplierID = Suppliers.SupplierID;|
GROUP BY  Groups rows based on a column  |SELECT CategoryID, COUNT(*) 
FROM Products GROUP BY CategoryID;|
HAVING  Filters groups based on a condition  |SELECT CategoryID, 
COUNT(*) FROM Products GROUP BY CategoryID HAVING COUNT(*) > 5;|
INSERT INTO  Inserts new records into a table  |INSERT INTO Products 
(ProductName, UnitPrice) VALUES ('Chai', 18.00);|
UPDATE  Modifies existing records in a table  |UPDATE Products SET 
UnitPrice = 20 WHERE ProductID = 1;|
DELETE FROM  Deletes records from a table  |DELETE FROM Products WHERE 
ProductID = 1;|
I hope this updated version of the SQL cheatsheet with examples based on 
the Northwind database schema is helpful for you to practice with.   

Q: Repeat, for SPARQL using DBpedia for examples.
A:
Sure, here is the SPARQL cheatsheet presented in a markdown table inside 
a code block with an additional column for actual usage examples using 
DBpedia for the examples:

Command  Description  Example
SELECT  Retrieves data from one or more RDF graphs  |SELECT ?person 
?birthdate WHERE { ?person dbo:birthDate ?birthdate } LIMIT 10|
DISTINCT  Retrieves unique values  |SELECT DISTINCT ?category WHERE { 
?product dcterms:subject ?category }|
WHERE  Filters RDF triples based on a condition  |SELECT ?film WHERE { 
?film rdf:type dbo:Film . ?film dbo:starring dbr:Harrison_Ford . }|
FILTER  Filters query results based on a condition  |SELECT ?film WHERE 
{ ?film rdf:type dbo:Film . ?film dbo:budget ?budget . FILTER(?budget > 
100000000) }|
UNION  Combines the results of two or more queries  |SELECT ?name WHERE 
{ { ?person foaf:name ?name } UNION { ?organization foaf:name ?name } }|
OPTIONAL  Retrieves optional RDF triples  |SELECT ?book ?author WHERE { 
?book rdf:type dbo:Book . OPTIONAL { ?book dbo:author ?author } }|
ORDER BY  Sorts the query results  |SELECT ?person ?birthdate WHERE { 
?person dbo:birthDate ?birthdate } ORDER BY DESC(?birthdate) LIMIT 10|
LIMIT  Limits the number of results returned  |SELECT ?person WHERE { 
?person rdf:type dbo:Person } LIMIT 10|
GROUP BY  Groups query results based on a variable  |SELECT ?category 
(COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } 
GROUP BY ?category|
HAVING  Filters groups based on a condition  |SELECT ?category 
(COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } 
GROUP BY ?category HAVING (COUNT(?product) > 100)|

Note: The examples above assume the use of the DBpedia SPARQL endpoint 
(https://dbpedia.org/sparql). If you want to test these queries, you can 
use the DBpedia SPARQL endpoint or install your own copy of DBpedia.

Q: Redo for SPARQL including DESCRIBE, CONSTRUCT, COPY, and MOVE commands
A:
Sure, here is the SPARQL cheatsheet presented in a markdown table inside 
a code block with additional commands and actual usage examples using 
DBpedia for the examples:

Command  Description  Example
SELECT  Retrieves data from one or more RDF graphs  |SELECT ?person 
?birthdate WHERE { ?person dbo:birthDate ?birthdate } LIMIT 10|
DISTINCT  Retrieves unique values  |SELECT DISTINCT ?category WHERE { 
?product dcterms:subject ?category }|
WHERE  Filters RDF triples based on a condition  |SELECT ?film WHERE { 
?film rdf:type dbo:Film . ?film dbo:starring dbr:Harrison_Ford . }|
FILTER  Filters query results based on a condition  |SELECT ?film WHERE 
{ ?film rdf:type dbo:Film . ?film dbo:budget ?budget . FILTER(?budget > 
100000000) }|
UNION  Combines the results of two or more queries  |SELECT ?name WHERE 
{ { ?person foaf:name ?name } UNION { ?organization foaf:name ?name } }|
OPTIONAL  Retrieves optional RDF triples  |SELECT ?book ?author WHERE { 
?book rdf:type dbo:Book . OPTIONAL { ?book dbo:author ?author } }|
ORDER BY  Sorts the query results  |SELECT ?person ?birthdate WHERE { 
?person dbo:birthDate ?birthdate } ORDER BY DESC(?birthdate) LIMIT 10|
LIMIT  Limits the number of results returned  |SELECT ?person WHERE { 
?person rdf:type dbo:Person } LIMIT 10|
GROUP BY  Groups query results based on a variable  |SELECT ?category 
(COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } 
GROUP BY ?category|
HAVING  Filters groups based on a condition  |SELECT ?category 
(COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } 
GROUP BY ?category HAVING (COUNT(?product) > 100)|
DESCRIBE  Retrieves RDF triples that describe a resource  |DESCRIBE 
<http://dbpedia.org/resource/Barack_Obama>|
CONSTRUCT  Generates an RDF graph based on a query pattern  |CONSTRUCT { 
?book dbo:author ?author } WHERE { ?book rdf:type dbo:Book . ?book 
dbo:author ?author }|
COPY  Copies a named graph from one location to another  |COPY 
<http://example.org/graph1> TO <http://example.org/graph2>|
MOVE  Moves a named graph from one location to another  |MOVE 
<http://example.org/graph1> TO <http://example.org/graph2>|

Note: The examples above assume the use of the DBpedia SPARQL endpoint 
(https://dbpedia.org/sparql). If you want to test these queries, you can 
use the DBpedia SPARQL endpoint or install your own copy of DBpedia.

​

-- 
Regards,

Kingsley Idehen 
Founder & CEO
OpenLink Software
Home Page:http://www.openlinksw.com
Community Support:https://community.openlinksw.com
Weblogs (Blogs):
Company Blog:https://medium.com/openlink-software-blog
Virtuoso Blog:https://medium.com/virtuoso-blog
Data Access Drivers Blog:https://medium.com/openlink-odbc-jdbc-ado-net-data-access-drivers

Personal Weblogs (Blogs):
Medium Blog:https://medium.com/@kidehen
Legacy Blogs:http://www.openlinksw.com/blog/~kidehen/
               http://kidehen.blogspot.com

Profile Pages:
Pinterest:https://www.pinterest.com/kidehen/
Quora:https://www.quora.com/profile/Kingsley-Uyi-Idehen
Twitter:https://twitter.com/kidehen
Google+:https://plus.google.com/+KingsleyIdehen/about
LinkedIn:http://www.linkedin.com/in/kidehen

Web Identities (WebID):
Personal:http://kingsley.idehen.net/public_home/kidehen/profile.ttl#i
         :http://id.myopenlink.net/DAV/home/KingsleyUyiIdehen/Public/kingsley.ttl#this

Received on Monday, 1 May 2023 21:14:01 UTC