---
title: "‘SELECT’ command with SQL operator"  
description: "There is lots of operator available in SQL server database such as assignment operator, bitwise operator, logical operator, comparison operator etc. H"  
author: "Anonymous User"  
published: 2011-07-08  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/557/select-command-with-sql-operator  
category: "database"  
tags: ["database"]  
reading_time: 3 minutes  

---

# ‘SELECT’ command with SQL operator

##### SQL SELECT command with AND/OR/Not Equal operator

There is lots of operator available in SQL [server database](https://www.mindstick.com/forum/159667/how-to-migrate-the-sql-server-database-to-a-lower-version) such as [assignment](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment) operator, [bitwise operator](https://answers.mindstick.com/qa/104698/what-is-a-bitwise-operator), logical operator, [comparison](https://www.mindstick.com/articles/23182/comparison-maruti-suzuki-celerio-v-s-tata-tiago) operator etc. Here we will discuss some important operator which is used widely in [SQL server](https://www.mindstick.com/articles/34/create-table-in-microsoft-sql-server) database.

##### SELECT command with AND operator:

The AND operator displays a record if both the first [condition](https://www.mindstick.com/forum/12711/select-query-with-and-condition) and the second condition is true.

##### Syntax:

SELECT [[COLUMN NAME](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query)] | [ALL] FROM <TABLE NAME> WHERE <FIRST_CONDITION> AND <SECOND_CONDITION>

##### Example:

```
 ---- SELECT USERLOGININFO ROW FIELD WHERE BOTH CONDITION TRUE  SELECT * FROM USERLOGININFO WHERE id = 103 AND NAME = 'HAPPY'
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/1c552db2-20c2-4a3d-991e-505063b86634.png)

##### Select command with OR operator:

The OR operator displays a record if either the first condition or the second condition is true.

**Syntax:** SELECT [COLUMN NAME] | [ALL] FROM <TABLE NAME> WHERE <FIRST_CONDITION> AND <SECOND_CONDITION>

##### Example:

```
 ---- SELECT USERLOGININFO ROW FIELD WHERET ONE CONDITION TRUE  SELECT * FROM USERLOGININFO WHERE id = 103 OR id=102
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/50e702b0-c2b2-4858-90c8-88e3baaed5ca.png)

##### SELECT command with AND/OR operator:

We can use ‘AND’ and ‘OR’ operator both concurrently.

##### Syntax:

SELECT [SPECIFIED COLUMN NAME] | [ALL] FROM <TABLE NAME> WHERE <CONDITION1> AND/OR <CONDITON WITHIN CONDITON> OR DO IT VICE VERSA.

##### Example:

```
---- SELECT USERLOGININFO ROW FIELD WHERET TWO CONDITION TRUE  SELECT * FROM USERLOGININFO WHERE id = 103 AND(Name = 'HAPPY' OR Name ='VARUNSINGH')
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/f203acbc-0486-41c2-bf53-134f91994a62.png)

##### SELECT command with NOT EQUAL (<>) operator:

Not Equal (<>) operator displays a records when condition not equal to provide condition.

##### Syntax:

SELECT [COLUMN NAME] | [ALL] FROM <TABLE_NAME> WHERE <CONDITION>

##### Example:

```
---- SELECT USERLOGININFO ROW FIELD WHERET CONDITION TRUE  SELECT * FROM USERLOGININFO WHERE id <> 103
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/4934f132-256a-4411-bfb8-1346ae7f8583.png)

##### SELECT command with ‘LIKE’ operator:

The LIKE operator is used in a [WHERE clause](https://www.mindstick.com/interview/1909/when-do-you-use-where-clause-and-when-do-you-use-having-clause) to search for a specified pattern in a column. With ‘Like’ operator we must be use SQL wildcards for search data in specified pattern.

##### Syntax:

SELECT [SPECIFIED _COLUMN_ NAME] | [ALL] FROM <TABLE_NAME> WHERE [COLUMN_NAME] LIKE [SEARCH_PATTERN]

##### Example:

```
---- SELECT USERLOGININFO ROW FIELD WHERE SEARCH PATTERN MATCH  SELECT * FROM USERLOGININFO WHERE Name like 'HA%'
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/ac7443a8-4f76-4685-8a2c-837d833af883.png)

##### SELECT command with IN operator:

The IN operator allows you to specify multiple values in a WHERE clause and retrieve that data field value where condition match.

##### Syntax:

SELECT [SPECIFIED_COLUMN_NAME] | [ALL] FROM <TABLE_NAME> WHERE [COLUMN_NAME] IN <VALUE1, VALUE2, …………….VALUEN>

##### Example:

```
---- SELECT USERLOGININFO ROW FIELD WHERE SEARCH PATTERN MATCH  SELECT * FROM USERLOGININFO WHERE id in (101,102,103,104,105,106)
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/f21fbc0e-3fef-4bc8-9c70-e8b01b41a56e.png)

##### SELECT command with UNION operator:

The UNION operator is used to combine the result-set of two or more SELECT statements. Notice that each [SELECT statement](https://www.mindstick.com/forum/160076/explain-the-sql-select-statement-and-how-it-s-used-to-search-for-data-in-a-database) within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

##### Syntax:

SELECT [SPECIFIED_COLUMN_NAME] | [ALL] FROM <TABLE _NAME 1>

UNION

SELECT [SPECIFIED_COLUMN_NAME] | [ALL] FROM <TABLE _NAME 2>

##### Example:

```
  SELECT * FROM STUDENT_DETAIL  UNION   SELECT * FROM STUDENT_DETAILS2
```

![‘SELECT’ command with SQL operator](https://www.mindstick.com/mindstickarticle/1216a153-610b-41f1-b51b-3035c069ffd7/images/41bcabc0-d6cc-41ba-b818-b4d855af3159.png)

There is a little difference between ‘UNION ‘and ‘UNION ALL’ in case of ‘UNION ALL’ duplicate data are consider where as in case ‘UNION’ does not.

---

Original Source: https://www.mindstick.com/articles/557/select-command-with-sql-operator

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
