I have one question about LINQ, I dont know how to get the result I need.
In my social network, I have the followers board, and I also have a search box to find the followers related by name or email.
My problem is, I dont know how to get this result. Having the Nickname or Email of the user, search the related followers.
This is my Followers table:
----------------------------
| ID | UserID | FollowerID |
----------------------------
My User table (only the columns I need)
-------------------------------------
| ID | Email | Nickname | Thumbnail |
-------------------------------------
My search box will be able to search results by Nickname or Email.
I tried to perform this query:
SELECT u.ID, u.Thumbnail, u.Nickname, u.Email
FROM dbo.[User] u
INNER JOIN dbo.Followers f
ON f.FollowerID = u.ID
WHERE f.UserID=4 and u.Nickname LIKE 'Laura'
ORDER BY u.Nickname
In this case, I would be UserID = 4, and I would be able to perform a search request of my followers…
Could anyone help me to perform this query?
May be you are looking for something like this.
Assuming that your search box contains the input
Laura, I believe that you want to search the columnsNickNameandEmailthat contain the textLaura.LIKE '%Laura%'would return rows containing the text Laura anywhere in the column.LIKE 'Laura%'would return rows where the column text begins with text Laura.Simply having
LIKE 'Laura'would return only rows that exactly match the text Laura.Sample data: