PostgreSQL AND ConditionIn this section, we are going to understand the working of PostgreSQL AND Condition, which is used with the WHERE clause to select unique data from more than one column in a table. And we also see examples of AND Condition with different queries such as INSERT, SELECT, UPDATE, and DELETE. Introduction of PostgreSQL AND ConditionIn PostgreSQL, the AND condition can combine with the SELECT, INSERT, UPDATE, and DELETE commands. In other words, we can say that the AND condition is used to specify the data if all the conditions separated by AND are TRUE. NOTE: The PostgreSQL AND condition allows us to return two or more conditions. And the PostgreSQL AND condition require any of the conditions that could be condition1, condition2, ...conditionN must be occurred in the data and involved in the output.PostgreSQL AND Condition SyntaxThe syntax of the PostgreSQL AND condition is as follows: In the above syntax, we have used the following parameter:
Examples of PostgreSQL AND ConditionLet us see different examples to understand how the PostgreSQL AND Condition works. Example of PostgreSQL AND condition with INSERT CommandWe will display how to use the AND condition with the INSERT command. For this, we are taking the employee and department table from the Organization database to insert the records from one table to another table. In the following example, we are inserting the record into the employee table from the department table. We take the phone and address columns records from the department table, the dept_id is less than 5, AND department_name is SALES. Output After executing the above command, we will get the below message window displaying that the value has been inserted successfully in the employee table. To check whether the records have been inserted into the employee table or not, we will use the SELECT command as follows: Output As we can see in the below screenshot that the PostgreSQL AND condition inserted one records into the employee table. Example of PostgreSQL AND condition with SELECT CommandIn the below example, we will display using the AND condition with the SELECT command having two conditions. For this, we are taking the Client table from the Javatpoint database to get the records from the table. We are using the AND condition with WHERE clause as we can see the following command: Output After executing the above command, we will get the following output: As we can see in the above screenshot, the PostgreSQL AND condition will return those clients information whose client_qualification is 'MBA' and have a client_salary less than or equal to 1000000. Example of PostgreSQL AND condition to Join two or more tablesTo Join various tables using PostgreSQL AND condition with SELECT command, we take the client and client_details tables from the Javatpoint database. The following command is a more complex query as compared to the above statement: Output After successfully executing the above command, we will get the following output: As we can see that the above command is working fine now; if we want to do it more precisely, we can write the above statement with the help of the PostgreSQL INNER Join condition. Output On implementing the above command, we will get the following result: As we can see in the above screenshot, the PostgreSQL AND condition will return those rows whose client_qualification is MBA. And the Client and Client_details tables are joined on client_id. Note:
Example of PostgreSQL AND Condition with UPDATE CommandIn the below example, we will display how to use the AND condition with the UPDATE command. For this, we are taking the summer_fruits table from the Javatpoint database. In the following command, the PostgreSQL AND condition is used to update the following values: The summer_fruits_name values to Strawberry, in the summer_fruits table where fruit_id is equal to 4 AND the summer_fruits_name is Guava. Output After executing the above command, we will get the below output, where we can see that the summer_fruits table has been updated successfully. We will now use the Select command to check whether the particular records have been updated or not in the summer_fruits table: Output On executing the above command, we will get the below result: Example of PostgreSQL AND condition with DELETE CommandIn the below example, we will display how to use the AND Condition with the DELETE command. In the below example, we take the Customer table from the Organization Database, deleting the particular records from the table. In the following command, the PostgreSQL AND Condition is used to delete all the records from the customer table where the first_name is 'Jane', and last_name is 'Miller'. Output After executing the above command, we will get the below message window displaying that the records have been deleted successfully from the customer table. We will now use the Select command to check whether the particular records have been deleted or not in the customer table: Output After successfully executing the above command, we will get the following output: Overview
Next TopicPostgreSQL OR Condition |