SPARQL & SQL: Debunking Similarities

First, if the term SPARQL is new to you it’s important to clarify the following: it is not a typo, and it is not SQL's long-lost cousin.

SPARQL is the standard query language and protocol for retrieving Linked Data from the web or RDF triple stores. Basically, if your information follows the RDF standard of being composed by a subject, predicate, and object, or it can be mapped to follow that standard, it can be queried by SPARQL.

The SPARQL specification was developed by the World Wide Web Consortium (W3C) and it describes the general rules its protocol follows. Overall, a SPARQL query can have one of 4 different forms (SELECT, DESCRIBE, CONSTRUCT or ASK) and it uses a set of triple patterns (subject, predicate, and object) where any variable can be switched for a wild card to obtain a specific result.

SPARQL query to find the author of the Harry Potter books from http://dbpedia.org

Figure 1 - SPARQL query to find the author of the Harry Potter books from http://dbpedia.org

Generally speaking, just like SQL, SPARQL is a widely-used query language. And while they might sound similar, they differ in various aspects.

For starters, SPARQL is designed to generate queries on data that doesn’t follow a fixed schema.

Therefore, its queries are centered on what the user wants to know from the data, rather than how the data is structured.

On the other hand, SQL is a query language for relational data. Hence, it relies heavily on the structure the data follows. This might cause SPARQL queries to seem more intuitive for new users than SQL queries. This ease of use is a major benefit to user adoption.

Figure 2 - SPARQL query to get the Harry Potter books' author's name from a local application.

Figure 2 - SPARQL query to get the Harry Potter books' author's name from a local application.

Figure 3 - Comparison of the same query using SQL assuming a test schema.

Figure 3 - Comparison of the same query using SQL assuming a test schema.

Furthermore, SPARQL has the advantage of having various public resources and end points to query from. Additionally, multiple sources of information can be included within a single query, allowing it to surpass the capabilities of a simple local search. Finally, it allows the user issuing the queries to enrich their information using external data provided by different organizations throughout the web.

However, SPARQL and SQL do share a few similarities. For example, they both have similar aggregate functions. They both let you query data even if certain constraints are not met. Finally, while their inner workings might differ, someone who has worked with SQL might find the language used in SPARQL quite familiar.

SPARQL is a powerful query language that can save development time and costs. The following complicated example highlights SPARQL’s abilities. Imagine you are given the task of finding the spouses of the people that got the highest score on the University graduating classes of the 40th to the 45th United States presidents' wives. Without SPARQL, you might tackle this by writing an initial query to pull information from the United States presidents' pages on Wikipedia. Then, a second query to retrieve their spouses followed by a third query to find their graduating university class. A fourth query would let you search for the highest score in that class. Lastly, a fifth query would let you figure out who the spouses of the top scoring people in that class are.

However, with SPARQL a single query that federates the appropriate data sources can provide the answer to this cumbersome question. No additional code would be necessary to format or filter out any additional information, simplifying the process greatly. In this example, SPARQL drastically reduces the effort and time to find the answer.

The power of SPARQL can unlock information substantially faster than other query languages. How can you use it to improve your business? Does your operations group need to access data from multiple databases? Could your sales and marketing teams benefit from faster customer database management?

Start querying the data contained within your Carbon LDP application using the Carbon LDP’s Workbench’s SPARQL Client, or use the Carbon LDP’s Javascript SDK’s SPARQLER (SPARQL query builder). At Base22 we love solving problems. Reach out to us here to learn how we can help your organization master your data or to learn about Carbon LDP.

Keep reading

Recent Blog Posts

  • All Post
  • Blog
Start Typing