Skip to main content

Analytics cookies

We’d like to use Google Analytics cookies to learn how this site is used and improve it. Nothing is set unless you accept, and there are no advertising cookies. Change your mind anytime under “Cookie settings” in the footer. Privacy policy

SPARQL & SQL: Debunking Similarities

SPARQL is not SQL’s long-lost cousin. How the query language for Linked Data differs from SQL, what the two share, and why one federated query can replace several.

· 3 min read

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 code retrieving the author of Harry Potter from DBpedia

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.

SPARQL query code retrieving the author's name for Harry Potter via DBpedia and FOAF

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

SQL query code joining BOOK, AUTHOR and BOOK_AUTHOR tables to select the author's name for the book Harry Potter

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.

Topics

  • Development & integration
  • AI & data
  • AI & data

    We turned our old tools off last, not first

    In fourteen weeks we moved our company’s time, expenses and invoicing onto a platform we built ourselves. The day the old time tracker went quiet, nobody noticed. That was the plan.

    Article · 6 min read

  • Development & integration

    A Quick Guide through Custom Web Components

    Custom web components are part of the HTML standard. How they help you keep your brand’s promise, secure your ability to deliver and make your developers more effective.

    Article · 4 min read

Bring us the hard problem.

Book 30 minutes with the senior people who would do the work.

Or write to info@base22.com