Simple Sql Server Query Clarification On Finding A Record Using Two Conditions
I'm pretty new to SQL and would like some help with the following question: What query would I run to find records that have a first name of 'John' AND a last name of 'Doe'? If I
Solution 1:
Following (exact same) query as yours give the results you specify.
;WITH q AS (
SELECT ID =1, Fname ='John', Lname ='Doe'UNIONALLSELECT2, 'Barry', 'Singer'UNIONALLSELECT3, 'John', 'Doe'UNIONALLSELECT4, 'James', 'Brown'
)
SELECT*FROM q
WHERE Fname ='John'AND Lname ='Doe'
Results
ID Fname Lname
----------- ----- ------ 1 John Doe
3 John Doe
(2rows affected)
Solution 2:
Seems that your query should work. Are you sure you have typed the table name correctly? What error are you receiving? This should also work, just replace tableName
with the name of your table:
SELECT*FROM tableName WHERE Fname ='John'AND LName ='Doe'
Here's an interactive example showing that your original query should work.
Post a Comment for "Simple Sql Server Query Clarification On Finding A Record Using Two Conditions"