Results 1 to 2 of 2

Thread: Simple SQL Select Query Question

  1. #1
    Join Date
    Mar 2008
    Posts
    3

    Simple SQL Select Query Question



    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

  2. #2
    Join Date
    Mar 2008
    Posts
    2
    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

    Quote Originally Posted by MrQuestions


    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

Similar Threads

  1. Query to Access database thru .ASP using SQL
    By JeratBP in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 22 Mar 2007, 09:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •