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 try this, it doesn't work:
select * from tableNames
where (FName = 'John') and (LName = 'Doe')
Thanks,开发者_高级运维 Ray
Following (exact same) query as yours give the results you specify.
;WITH q AS (
SELECT ID = 1, Fname = 'John', Lname = 'Doe'
UNION ALL SELECT 2, 'Barry', 'Singer'
UNION ALL SELECT 3, 'John', 'Doe'
UNION ALL SELECT 4, 'James', 'Brown'
)
SELECT *
FROM q
WHERE Fname = 'John' AND Lname = 'Doe'
Results
ID Fname Lname
----------- ----- ------
1 John Doe
3 John Doe
(2 rows affected)
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.
精彩评论