Skip to content
Advertisement

Select with joins in a unique table system

I am trying to build an SQL query on an omekaS database to extract books with a specific title and date.

In this system, the table holding the values is called value, and the relevant attributes are as so :

The resource_Id is the identifier through the db Value is one field; like the book “Moby Dick” written in 1822 (random date) would look like this in db. Type tells us what is it (arbitrarily, 1 is titles and 2 is publishing year)

Id resource_id type value
1 1 1 Moby dick
2 1 2 1822

I need to take all books with a certain title, published in a set of years

Basically

I get lost, and I have no idea how to do this.

What would be the best way?

Thanks

Advertisement

Answer

If you need to check more types, you can check with AND EXISTS (SELECT 1 FROM ...WHERE type = 3 AND ...) if the conditions are met

I renemd the table name, it is confusing to use cloumn names and table names with identical names.

resource_id | value    
----------: | :--------
          1 | Moby Dick

db<>fiddle here

And if you want to have them in a row

resource_id | value     | value
----------: | :-------- | :----
          1 | Moby Dick | 1822 

db<>fiddle here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement