I am trying to figure out how I can select multiple rows from a table, based on the id column. Something like this:
select * from table where id=1 or id=2 or id=3
Should I loop through every id and perform a query for each iteration?
Removing duplicate rows from a query result set in PostgreSQL can be done using the SELECT statement with the DISTINCT clause. It keeps one row for each group of duplicates. The DISTINCT clause can be used for a single column or for a list of columns.
In an Oracle database, the ROWID pseudocolumn is a physical address of a row in a table. This pseudocolumn is used to uniquely identify a row even if the primary key isn't present on a table. PostgreSQL has a similar pseudocolumn called ctid , but it cannot be used as a ROWID .
Using Joins Joins are used to retrieve rows from two or more tables, based on a related column between those tables.
Let's make a function that returns all the rows of a table whose name you pass in as a parameter. create or replace function GetRows(text) returns setof record as ' declare r record; begin for r in EXECUTE ''select * from '' || $1 loop return next r; end loop; return; end ' language 'plpgsql';
select *
from table
where id in (1, 2, 3)
If you want to have results where id = 1
and results where id = 2
and results where id = 3
, you have to use a different logic.
You actually want results where id = 1 or id = 2 or id = 3
Or you want results where id in (1, 2, 3)
Or you want results where id between 1 and 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With