selecting multiple columns with where clause in sql

sql combine two columns in where clause
multiple columns in in clause sql server
multiple columns in where clause in mysql
sql two different where conditions for two columns
sql where combination of two fields
sql select where two columns match
sql where multiple conditions
sql where multiple values

A student studies more than 1 optional subject. I have created two columns named optional_sub1 and optional_sub2. I want to select only one column from two using sql statement. SQL statement is as under:

$sql= "SELECT * 
       FROM students 
       WHERE class = '$SelectClass' 
       && optional_sub1 = '$SelectSubject' 
       || optional_sub2 = '$SelectSubject'";

Please modify the above syntax. Thanks.

USE AND/OR for &&/|| operator respectively

$sql= "SELECT * FROM students WHERE class = '$SelectClass' 
and (optional_sub1 = '$SelectSubject' or optional_sub2 = '$SelectSubject')"

'In' clause in SQL server with multiple columns, This syntax doesn't exist in SQL Server. Use a combination of And and Or . SELECT * FROM <table_name> WHERE (value_type = 1 and� To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate, from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.

Use AND/OR instead of C#/Java operators.

$sql= "SELECT * FROM students 
       WHERE class = '$SelectClass' 
             and (optional_sub1 = '$SelectSubject' 
                  optional_sub2 = '$SelectSubject'");

SQL with 2 columns in where condition, I'm having trouble creating a view in cache with query like: SELECT column1, column2, column 3. FROM table. WHERE (column1, columnn 2)� SELECT column1, column2, column 3 FROM table WHERE (column1, columnn 2) IN (SELECT c1, c2 FROM table2 GROUP BY c1) ORDER BY column1 . I think the problem is in where clause, because it cannot take two columns . the exact error: [SQLCODE: <-1>:<Invalid SQL statement>] [%msg: < ) expected, , found^ (column1,>] Any idea on how to solve this? Thank

FROM students 
WHERE class = '$SelectClass' 
and optional_sub1 = '$SelectSubject' 
and optional_sub2 = '$SelectSubject';

Specify Multiple Search Conditions for Multiple Columns, In the Filter column for the second data column, specify the second condition. The Query and View Designer creates a WHERE clause that� Multiple row subquery returns one or more rows to the outer SQL statement. You may use the IN, ANY, or ALL operator in outer query to handle a subquery that returns multiple rows. See the details.

SELECTing multiple columns, Luckily, SQL makes this really easy. To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two� DISTINCT on multiple columns. Sample Select statement. Select with distinct on two columns. Select with distinct on three columns. Select with distinct on all columns of the first query. Select with distinct on multiple columns and order by clause. Count() function and select with distinct on

selecting where two columns are in a set, Is there a construct in SQL that would allow me to do something like the following: Yes, there is, almost exactly as you wrote it. Just put col1, col2 inside� SQL HOME SQL Intro SQL Syntax SQL Select SQL Select Distinct SQL Where SQL And, Or, Not SQL Order By SQL Insert Into SQL Null Values SQL Update SQL Delete SQL Select Top SQL Min and Max SQL Count, Avg, Sum SQL Like SQL Wildcards SQL In SQL Between SQL Aliases SQL Joins SQL Inner Join SQL Left Join SQL Right Join SQL Full Join SQL Self Join SQL

Multiple Column Subqueries, no rows selected. Returning Nulls in the Resulting Set of a Subquery. The SQL statement on the slide� SELECT * FROM T1 WHERE CONCAT(a,"_",b) IN (SELECT CONCAT(a,"_",b) FROM T2) Note that if your columns are numeric, some SQL dialects will require you to cast them to strings first. I believe SQL server will do this automatically.

  • You are vulnerable to SQL injection! Always parameterise your queries.
  • Worked for me. thanks alot. but if i want to add optional_sub3 also, can i use $sql= "SELECT * FROM students WHERE class = '$SelectClass' and (optional_sub1 = '$SelectSubject' or optional_sub2 = '$SelectSubject' or optional_sub3 = '$SelectSubject')"
  • @Akhtar, yes you can
  • optional_sub1 = '$SelectSubject' and optional_sub2 = '$SelectSubject' is not in OP's requirements and this propably will result in empty resultset