Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oL5Tc-0001OL-6b for pgsql-sql@arkaria.postgresql.org; Mon, 08 Aug 2022 16:19:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oL5Ta-0005mV-Ql for pgsql-sql@arkaria.postgresql.org; Mon, 08 Aug 2022 16:19:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oL5S2-0001Nq-27 for pgsql-sql@lists.postgresql.org; Mon, 08 Aug 2022 16:17:58 +0000 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oL5Rz-00027a-6Q for pgsql-sql@lists.postgresql.org; Mon, 08 Aug 2022 16:17:57 +0000 Received: from [192.168.1.125] (unknown [92.184.98.198]) (Authenticated sender: pierremariechevalier@free.fr) by smtp4-g21.free.fr (Postfix) with ESMTPSA id 7240819F72E for ; Mon, 8 Aug 2022 18:17:51 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------qf8iVnZNmieKXvLW00YmRE3Q" Message-ID: Date: Mon, 8 Aug 2022 18:17:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: select items based on 2 columns Content-Language: fr To: pgsql-sql@lists.postgresql.org References: From: Pierre Chevalier In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------qf8iVnZNmieKXvLW00YmRE3Q Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 --------------qf8iVnZNmieKXvLW00YmRE3Q Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
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.