public inbox for [email protected]
help / color / mirror / Atom feedFrom: Pierre Chevalier <[email protected]>
To: [email protected]
Subject: Re: select items based on 2 columns
Date: Mon, 8 Aug 2022 18:17:50 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+i5JwYCPBDcenq_godJqtjApLyOeJHxo-Joova3wrAYtM6QOA@mail.gmail.com>
References: <CA+i5JwYCPBDcenq_godJqtjApLyOeJHxo-Joova3wrAYtM6QOA@mail.gmail.com>
Hello,
Short answer:
SELECT id FROM tbl WHERE in and out;
BUT this will never work as is.
Longer answer:
First of all, it would be better not to name fields with word having a meaning in SQL: "in" is not accepted as a valid field name.
From now on, to get rid of this problem, I renamed the in and out fields by appending an "x" at the end: "in" becomes "inx" and "out" becomes "outx".
Here is the complete answer; I added some data matching your criteria:
-- Create the table:
CREATE TEMPORARY TABLE tbl (id integer, id_b integer, inx boolean, outx boolean);
-- Put some data into it:
INSERT INTO tbl (id, id_b, inx, outx) VALUES
(51, 57, false, false),
(51, 42, true, false),
(51, 32, false, false),
(51, 76, false, true),
(51, 49, true, false),
(51, 47, true, true);
-- Select id where inx is true and outx is true:
SELECT id FROM tbl WHERE inx and outx;
-- Output:
┌────┐
│ id │
├────┤
│ 51 │
└────┘
À+
Pierre
Le 08/08/2022 à 10:24, Shaozhong SHI a écrit :
> The following is the type of data:
>
> id id_b in out
> 51 57 false false
> 51 42 true false
> 51 32 false false
> 51 76 false true
> 51 49 true false
>
>
> How to do the following:
>
> select id from tbl if in is true and out is true are found?
>
> Regards,
>
> David
--
Pierre Chevalier
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: select items based on 2 columns
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox