How to select all the columns of a table except one column?
You can use this approach to get the data from all the columns except one:-
- Insert all the data into a temporary table
- Then drop the column which you dont want from the temporary table
- Fetch the data from the temporary table(This will not contain the data of the removed column)
- Drop the temporary table
Something like this:
SELECT * INTO #TemporaryTable FROM YourTableName
ALTER TABLE #TemporaryTable DROP COLUMN Columnwhichyouwanttoremove
SELECT * FROM #TemporaryTable
DROP TABLE #TemporaryTable
SQL - Exclude rows from SELECT statement if a certain column combination exists in that row
Since a row can only match one of those conditions at one time, you should be using OR
:
SELECT COLUMN1, COLUMN2, COLUMN3
FROM YourTable
WHERE NOT (
( COLUMN2 = 'A' AND COLUMN3 = 'B' )
OR
( COLUMN2= 'B' AND COLUMN3 = 'C' )
)
db<>fiddle here
Excluding some columns in a SELECT statement
The only way is to list all 9 columns.
Such as:
SELECT col1, col2, col3, col4, col5, col6, col7, col8, col9 FROM myTable
Related Topics
How to Select Records from Last 24 Hours Using SQL
SQL Server Plans:Difference Between Index Scan/Index Seek
T-Sql: How to Select Values in Value List That Are Not in the Table
Add a Row Number to Result Set of a SQL Query
Execute Table-Valued Function on Multiple Rows
How to Run SQL Statements on a Named Range Within an Excel Sheet
SQL Server Equivalent to MySQL's Explain
How to Setup a Linked Server to an Oracle Database on SQL 2000/2005
View or Temporary Table - Which to Use in Ms SQL Server
Work Around SQL Server Maximum Columns Limit 1024 and 8Kb Record Size
SQL to Determine Minimum Sequential Days of Access
Efficient Way of Getting @@Rowcount from a Query Using Row_Number
How to Restore Postgresql Dump File into Postgres Databases
Select from Table by Knowing Only Date Without Time (Oracle)
SQL Server Convert Select a Column and Convert It to a String
Ora-01861: Literal Does Not Match Format String
SQL Server Management Studio 2008 Runas User on Different Domain Over Vpn