Questions tagged [row-value-expression]

A row-value-expression is a SQL standard expression for specifying a row value. Other languages call this a record or a tuple.

A row-value-expression is a SQL standard expression for specifying a row value. Other languages call this a record or a tuple.

Definition

The SQL1992 Standard specifies a row value constructor as such:

<row value constructor> ::=
        <row value constructor element>
      | <left paren> <row value constructor list> <right paren>
      | <row subquery>

 <row value constructor list> ::=
      <row value constructor element>
          [ { <comma> <row value constructor element> }... ]

 <row value constructor element> ::=
        <value expression>
      | <null specification>
      | <default specification>

According to this definition, regular values and row values can thus be used interchangeably in SQL. This can be seen in expressions as these:

Using row values of degree = 1

SELECT * FROM table t
WHERE t.a = 1

Using row values of degree > 1

SELECT * FROM table t
WHERE (t.a, t.b) = (1, 2)

Support

Only few databases really support row value expressions as specified in the SQL standard. These include (with partial or full support):

  • DB2
  • HSQLDB
  • MYSQL
  • ORACLE
  • POSTGRES
20 questions
79
votes
9 answers

Using tuples in SQL "IN" clause

I have a table containing the fields group_id and group_type and I want to query the table for all the records having any tuple (group id, group type) from a list of tuples. For example, I want to be able to do something like: SELECT * FROM…
Rafid
  • 18,991
  • 23
  • 72
  • 108
17
votes
2 answers

SQL: tuple comparison

In my current application, I need to be able to do this type of query: SELECT MIN((colA, colB, colC)) FROM mytable WHERE (colA, colB, colC) BETWEEN (200, 'B', 'C') AND (1000, 'E', 'F') and get the answer of (333, 'B', 'B'), given this…
bukzor
  • 37,539
  • 11
  • 77
  • 111
12
votes
3 answers

Using tuples in SQL in clause

Given a database like this: BEGIN TRANSACTION; CREATE TABLE aTable ( a STRING, b STRING ); INSERT INTO aTable VALUES('one','two'); INSERT INTO aTable VALUES('one','three'); CREATE TABLE anotherTable ( a STRING, b STRING ); INSERT…
mr calendar
  • 945
  • 5
  • 11
  • 21
8
votes
3 answers

Exclude rows with null values

I'm doing a bunch of sum queries: SELECT col1 + col2 + col3 + ... Some of the values in some of the columns are null. I'm checking for them by doing: SELECT CASE WHEN col1 is not null and col2 is not null and ... I wonder if there is a more…
canisrufus
  • 665
  • 2
  • 6
  • 19
8
votes
3 answers

How to do tuple comparison?

Trying the same as this question but in SQLite. In my application I need to do this type of query: SELECT First, Last, Score FROM mytable WHERE ('John', 'Jordan', 5) <= (First, Last, Score ) AND (First, Last, Score) <= ('Mike', 'Taylor', …
bukzor
  • 37,539
  • 11
  • 77
  • 111
7
votes
4 answers

Is it possible to compare *tuples* in the `WHERE` clause of a SQL query?

Is it possible to compare tuples (thanks, a_horse_with_no_name) in the WHERE clause of a SQL query? That way, I could convert this: /* This is actually a sub-sub-sub-query in the middle * * of an incredibly complex stored procedure. …
isekaijin
  • 19,076
  • 18
  • 85
  • 153
6
votes
2 answers

Using IN with sets of tuples in SQL (SQLite3)

I have the following table in a SQLite3 database: CREATE TABLE overlap_results ( neighbors_of_annotation varchar(20), other_annotation varchar(20), set1_size INTEGER, set2_size INTEGER, jaccard REAL, p_value REAL, bh_corrected_p_value REAL, PRIMARY…
gotgenes
  • 38,661
  • 28
  • 100
  • 128
5
votes
5 answers

Multi keys in SQL WHERE IN clause

Say you have Accounts table where ID column is PK and TaxID+AccountNumber is unique constraint: select * from Accounts where ID in (100, 101) now you want to make similar query using the natural key: select * from Accounts where {TaxID,…
UserControl
  • 14,766
  • 20
  • 100
  • 187
5
votes
2 answers

T-SQL equivalent to oracle sql where clause with multiple columns

Let's look for example Oracle SQL, which works perfectly: Sample data: SQL> create table test (a number, b number); SQL> insert into test values(1, 1); SQL> insert into test values(1, 2); SQL> insert into test values(1, 3); SQL> insert into test…
4
votes
1 answer

Difference between null composite type and composite type with all null columns

Is there any difference between a null value and a row type where all columns are null? Postgres queries appear to be able to tell the difference (displaying null columns rather than a blank) and I want to know if there's anything I should be aware…
2
votes
1 answer

Tuple in IN clause in MS Access 2003

I wanted to make a query in MS Access 2003 (or just sql in VBA) which would have an IN clause working on tuples, i.e., I have to columns with year and month, and I would like to extract for example 2010-10 and 2012-03 using IN clause. For comparison…
MPękalski
  • 6,873
  • 4
  • 26
  • 36
2
votes
2 answers

SQLite tuples equality comparison

With PostgreSQL and MySQL it is all right to do something like SELECT * FROM mytable WHERE (column1, column2) = ('value1', 'value2'); When I tried the same thing on SQLite3, it gave me an exhausting error message: Error: near ",": syntax…
koniiiik
  • 4,240
  • 1
  • 23
  • 28
1
vote
2 answers

append value of next row with current row pandas groupby id

I have a dataframe as id status 1 owner 1 retail 1 shop 1 customer 2 owner 2 retail I created new column of Last status like id status Last status 1 owner NA 1 retail owner 1 shop retail 1 customer shop 2 owner NA 2 …
naina
  • 303
  • 3
  • 14
1
vote
1 answer

How to write a condition with more than one field with jooq

I would like to write a condition like the following with JOOQ AND (id,name) IN (('id1','name1'),('id2','name2'),...) I tried this syntax Condition condition= DSL.concat(idField,nameField).in(""); which generates concat(cast(`id` as char),…
mmounirou
  • 719
  • 6
  • 12
0
votes
0 answers

How to use the result column of ROW_NUMBER()OVER(ORDER BY FOO) in a aggregate function

Having the following requirements: A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to decimal places. Input…
1
2