Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use an asterisk (*) to filter a column in a WHERE clause under SQL Server 2008?

For example

SELECT * FROM movies WHERE director=*
like image 284
Scifiballer24 Avatar asked Jun 16 '11 18:06

Scifiballer24


People also ask

What does the * asterisk represent in a SQL statement?

The asterisk or star symbol ( * ) means all columns. The semi-colon ( ; ) terminates the statement like a period in sentence or question mark in a question.

Why should we not use * in SQL?

SELECT * return more data than required to the client which in turn will use more network bandwidth. This increase in network bandwidth also means that data will take a longer time to reach the client application which could be SSMS or your Java application server.

Which clause of SQL query can be used to filter the columns?

The SQL WHERE Clause The WHERE clause is used to filter records.

What is the use of * in SQL?

The second part of a SQL query is the name of the column you want to retrieve for each record you are getting. You can obviously retrieve multiple columns for each record, and (only if you want to retrieve all the columns) you can replace the list of them with * , which means "all columns".


2 Answers

No, you would need to use the LIKE operator and the % wildcard:

SELECT * FROM movies WHERE director like '%';
like image 115
The Evil Greebo Avatar answered Oct 24 '22 15:10

The Evil Greebo


You can use LIKE;

SELECT * FROM movies WHERE director LIKE '%' --all
SELECT * FROM movies WHERE director LIKE 'john landis' --exact
SELECT * FROM movies WHERE director LIKE 'steve%berg' --with wildcard
like image 33
Alex K. Avatar answered Oct 24 '22 15:10

Alex K.