If I have a SQL table that can be queried like this:
Select empname from mytable
Where empid=1;
What would an equivalent SPARQL query be?
If I have a SQL table that can be queried like this:
Select empname from mytable
Where empid=1;
What would an equivalent SPARQL query be?
As a few people have mentioned here and on your similar, previous question, you probably need to do some more reading about the nature of RDF-modeled data.
For Stack Overflow, you definitely need to get into the habit of showing your input data and whatever code you have written so far, even if it isn't working perfectly. In that case, you need to include the error message in your question.
Here's a self contained example in which I
The example is written in R, my strongest language. To be clear: you don't need to know anything about R to be good at RDF, SPARQL and other semantic technologies. If I were better at Java or Python, I would have written the example in one of those languages.
The relational (SQL) data must be converted to RDF before it can be queried with RDF. In the code below, I have done that by hand. See the end of the message for the nuts and bolts.
To review: this R code above demonstrates a SAPRQL query that is equivalent to the OP's SQL query. SQL queries are typically run against SQL databases, but I made this self-contained by running it against a dataframe.
SPARQL queries are run against RDF data, frequently in the form of a triplestore database. In my example, a string containing RDF triples is converted into an in-memory RDF model, and the SPARQL query is sent to that model.
So the question becomes, if you have data in a SQL database, how do you query the database's contents with SPARQL? As of Summer, 2017, this is an evolving topic. There are a variety of commercial and open-source tools that can help solve this problem, usually in one of two ways:
In either case, somebody will need to create a mapping from the SQL data into RDF format. This is required because SQL tables don't intrinsically have explicit semantics. Rows typically model individuals of some category, and columns typically represent properties or relationships of the individuals. RDF triples must have explicit subject-verb-object semantics.
Here are my recommended first steps for SQL-RDF mapping with Karma, which has a nice graphical interface. Similar results could be achieved with another R2RML mapper like D2RQ (works, but un-maintained for 3 years), ontop, or the R2RML parser.
44403425.owlOpen the attached ontology in Karma (import->from file)mytable.csv, which is intended to represent a dump from a SQL database. If you want to work with a live database, you will be responsible for making sure the right database drivers are installed. In that case, useimport->Database Tableinstead.mytable-model.ttl. Click on the pull-down on the left of the gray bar near the top of the Karma web page. ChooseApply R2RML model->from fileand loadmytable_model.ttlPublish->RDF. Accept the suggested settings.OpenRDFat the right of the top black bar. Right click that link to open it in a new browser window/tab.karma_datarepository. You can now use any of theExplorelinks on the left, including the (SPARQL)QuerylinkFinally, if you want to use an R2RML mapper other than Karma, you can use a mapping file similar to (but not identical to)
mytable-model.ttl. Karma does some data manipulations with snippets of Python, which get embedded in JSON. That JSON becomes the huge object of akm-dev:hasWorksheetHistorytriple. I don't believe that all R2RML parsers would recognize the Python/JSON.44403425.owl
mytable.csv
mytable-model.ttl