Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a table contains a row with a specific column value

In T-SQL syntax, how could I check to see if a table has a row with a a column matching a particular value? I am using SQL Server 2012 and am completely new to it.

Any and all help is greatly appreciated.

like image 321
user1067257 Avatar asked Feb 25 '13 02:02

user1067257


People also ask

How do you check if a row exists in a table?

To test whether a row exists in a MySQL table or not, use exists condition. The exists condition can be used with subquery. It returns true when row exists in the table, otherwise false is returned. True is represented in the form of 1 and false is represented as 0.

How do I SELECT a specific value from a column in SQL?

The syntax is: SELECT column1, column2 FROM table1, table2 WHERE column2='value'; In the above SQL statement: The SELECT clause specifies one or more columns to be retrieved; to specify multiple columns, use a comma and a space between column names.


1 Answers

IF EXISTS (SELECT * FROM TABLE WHERE [column] = 'column_value')
  -- The value 'column_value' was found in column [column]
  • IF
  • EXISTS
  • SELECT
like image 59
Brad Christie Avatar answered Oct 09 '22 14:10

Brad Christie