PDA

View Full Version : Simple SQL Select Query Question



MrQuestions
19 Mar 2008, 05:35 PM
:smash:

Hi,

I'm trying to return all of rows by applying a simple query to my database, however not all of the rows are being returned. The simple SQL query is:

SELECT `member_id` FROM `tags` WHERE `tagname`='baseball'

The rows that are left out are those in which the variable being searched for is not the first record listed in the table for a corresponding record. For example, the query of the "tags" table (below) for 'baseball' above returns only member_ids 10 and 12. member_id 11 also has a tag: "baseball" but it is not being returned. What do I need to add to my query in order to return all of the member_ids that correspond, and not just the "first" ones? Thanks in advance!

table: tags
member_id -- tagname
10 -- baseball
10 -- free
10 -- stars
11 -- fakeguy
11 -- baseball
11 -- free
12 -- baseball
12 -- test
12 -- fantasy
12 -- sports
13 -- basketball
13 -- hoops
13 -- ncaa

justinmc
19 Mar 2008, 07:26 PM
thinking about the obvious here, but are your sure that each of those rows has the word "baseball" spelled correctly? Also, it's difficult to tell with just that snippet of your database, but unless tagname is a foreign key, my guess is your database could also benefit from some normalization. It'll only help in the long run.

Justin


:smash:

Hi,

I'm trying to return all of rows by applying a simple query to my database, however not all of the rows are being returned. The simple SQL query is:

SELECT `member_id` FROM `tags` WHERE `tagname`='baseball'

The rows that are left out are those in which the variable being searched for is not the first record listed in the table for a corresponding record. For example, the query of the "tags" table (below) for 'baseball' above returns only member_ids 10 and 12. member_id 11 also has a tag: "baseball" but it is not being returned. What do I need to add to my query in order to return all of the member_ids that correspond, and not just the "first" ones? Thanks in advance!

table: tags
member_id -- tagname
10 -- baseball
10 -- free
10 -- stars
11 -- fakeguy
11 -- baseball
11 -- free
12 -- baseball
12 -- test
12 -- fantasy
12 -- sports
13 -- basketball
13 -- hoops
13 -- ncaa