Skip to content
Advertisement

How to search from a table using join?

So I have three tables as follows:

Members -> id, userId, accountId

Account -> id, name

User -> id, firstName, lastName, email

The above sql gives me correct number of data as follows.

But when I do a search on the users from the same table, it gives me data also from accountId other than 1 when it should only give data from accountId 1.

This gives me all four data:

The result should display only from accountID 1 but since there is matching in the name, its giving more result than expected.

The above query matches the LIKE with the user and returns members other than from accountId 1 which is true, but how can I write the query so that members are listed from accountId and also can be searched via name, email in users table.

Advertisement

Answer

Just keep in simple, something like this perhaps.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement