Like RDBMS, OrientDB underpins various kinds of SQL questions to recover the records from the information base. While recovering the records we have various varieties or alternatives of inquiries alongside the select assertion.
The accompanying assertion is the essential sentence structure of the SELECT order.
SELECT [ <Projections> ] [ FROM <Target> [ LET <Assignment>* ] ]
[ WHERE <Condition>* ]
[ GROUP BY <Field>* ]
[ ORDER BY <Fields>* [ ASC|DESC ] * ]
[ UNWIND <Field>* ]
[ SKIP <SkipRecords> ]
[ LIMIT <MaxRecords> ]
[ FETCHPLAN <FetchPlan> ]
[ TIMEOUT <Timeout> [ <STRATEGY> ] ]
[ LOCK default|record ]
[ PARALLEL ]
[ NOCACHE ]
Following are the insights concerning the alternatives in the above grammar.
<Projections> − Indicates the information you need to separate from the inquiry therefore records set.
FROM − Indicates the item to question. This can be a class, group, single Record ID, set of Record IDs. You can determine every one of these articles as target.
- WHERE − Specifies the condition to channel the outcome set.
- LET − Indicates the setting variable which are utilized in projections, conditions or sub inquiries.
- Gathering BY − Indicates the field to amass the records.
- Request BY − Indicates the documented to orchestrate a record all together.
- Loosen up − Designates the field on which to loosen up the assortment of records.
- SKIP − Defines the quantity of records you need to skip from the beginning of the outcome set.
- Breaking point − Indicates the greatest number of records in the outcome set.
- FETCHPLAN − Specifies the procedure characterizing how you need to get results.
- Break − Defines the most extreme time in milliseconds for the question.
- LOCK − Defines the locking procedure. DEFAULT and RECORD are the accessible lock techniques.
- Equal − Executes the inquiry against 'x' simultaneous strings.
- NOCACHE − Defines if you need to utilize reserve.
Example
How about we consider the accompanying Customer table made in the past part.
Sr.No. | Name | Age |
---|---|---|
1 | Satish | 25 |
2 | Krishna | 26 |
3 | Kiran | 29 |
4 | Javeed | 21 |
5 | Raja | 29 |
Attempt diverse select inquiries to recover the information records from the Customer table.
Method 1 − You can utilize the accompanying question to choose all records from the Customer table.
orientdb {db = demo}> SELECT FROM Customer
In the event that the above question is executed effectively, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:0|Customer|1 |satish |25
1 |#11:1|Customer|2 |krishna|26
2 |#11:2|Customer|3 |kiran |29
3 |#11:3|Customer|4 |javeed |21
4 |#11:4|Customer|5 |raja |29
----+-----+--------+----+-------+----
Method 2 − Select all records whose name begins with the letter 'k'.
orientdb {db = demo}> SELECT FROM Customer WHERE name LIKE 'k%'
Or on the other hand you can utilize the accompanying inquiry for the above model.
orientdb {db = demo}> SELECT FROM Customer WHERE name.left(1) = 'k'
In the event that the above inquiry is executed effectively, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:1|Customer|2 |krishna|26
1 |#11:2|Customer|3 |kiran |29
----+-----+--------+----+-------+----
Method 3 −Select id, name records from the Customer table with names in capitalized letters.
orientdb {db = demo}> SELECT id, name.toUpperCase() FROM Customer
In the event that the above inquiry is executed effectively, you will get the accompanying yield.
----+--------+----+-------
# |@CLASS |id |name
----+--------+----+-------
0 |null |1 |SATISH
1 |null |2 |KRISHNA
2 |null |3 |KIRAN
3 |null |4 |JAVEED
4 |null |5 |RAJA
----+--------+----+-------
Method 4 − Select all records from the Customer table where age is in the scope of 25 to 29.
orientdb {db = demo}> SELECT FROM Customer WHERE age in [25,29]
In the event that the above question is executed effectively, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:0|Customer|1 |satish |25
1 |#11:2|Customer|3 |kiran |29
2 |#11:4|Customer|5 |raja |29
----+-----+--------+----+-------+----
Method 5 − Select all records from the Customer table where any field contains the word 'sh'.
orientdb {db = demo}> SELECT FROM Customer WHERE ANY() LIKE '%sh%'
On the off chance that the above inquiry is executed effectively, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:0|Customer|1 |satish |25
1 |#11:1|Customer|2 |krishna|26
----+-----+--------+----+-------+----
Technique 6 − Select all records from the Customer table, requested by age in dropping request.
orientdb {db = demo}> SELECT FROM Customer ORDER BY age DESC
In the event that the above inquiry is executed effectively, you will get the accompanying yield.
----+-----+--------+----+-------+----
# |@RID |@CLASS |id |name |age
----+-----+--------+----+-------+----
0 |#11:2|Customer|3 |kiran |29
1 |#11:4|Customer|5 |raja |29
2 |#11:1|Customer|2 |krishna|26
3 |#11:0|Customer|1 |satish |25
4 |#11:3|Customer|4 |javeed |21
----+-----+--------+----+-------+----