This is a discussion on "Simple SQL Select Query Question" within the Databases section. This forum, and the thread "Simple SQL Select Query Question are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Simple SQL Select Query Question
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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 `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 ids 10 and 12. 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 ids that correspond, and not just the "first" ones? Thanks in advance! table: tags 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 |
|
|
|
|||
|
Re: Simple SQL Select Query Question
I don't see what's the problem here??
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
|||
|
Re: Simple SQL Select Query Question
The problem is that when I run the query, it only returns IDs 10 and 12. ID 11 also has a tag called "baseball," so I'm wondering why ID 11 isn't included when the query is run... seems to me that it should be, although admittedly it's been awhile since I built a web app so I'm surely rusty.
I tried SELECT * it returns only ID 10 and 12 (except it returns the 'tagname' too of course). The purpose is that I'm trying to create an algorithm that ranks and displays "related articles" based on the tags attached to the current article. Thanks for the reply! |
|
|||
|
Re: Simple SQL Select Query Question
Are you sure ID 11 has "baseball" as the current value?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
|||
|
Re: Simple SQL Select Query Question
You have only two columns, try to add one more with unique value like a key.
If this is redundant and you want all rows just SELECT * FROM tags; |
|
|||
|
Re: Simple SQL Select Query Question
But he only want to select a field (tagname) with the value "baseball"?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
|
|||
|
Re: Simple SQL Select Query Question
Then like you say
"SELECT * FROM tags WHERE tagname = 'baseball'" or Questions you can try with something like "SELECT * FROM tags WHERE tagname LIKE 'baseball'" also can do with regular extensions but i think is not necessary. It is quite simple query why give wrong answers. I advise you to list your rows again and carefully view it. Good luck |
|
|||
|
Re: Simple SQL Select Query Question
That's what he is doing now but the SQL is only returning 2 row of data instead of 3!
I think there must be something wrong with the tagname value...
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Please Help with (should be) simple count() query. | MrQuestions | Databases | 2 | Mar 23rd, 2008 20:42 |
| MYSQL/PHP Query question | andrewlondon | Databases | 1 | Sep 19th, 2007 11:26 |
| Simple CSS Question | welshie | Web Page Design | 9 | Jan 31st, 2007 12:22 |
| Query question - can I return values for records not found? | Donny Bahama | Databases | 5 | Aug 21st, 2006 11:39 |
| a simple question (I think) | Colm Osiris | Web Page Design | 2 | Feb 5th, 2006 09:17 |