Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old March 19th, 2008, 06:52 PM   #1
New Member
 

Join Date: Mar 2008
Location: states
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 MrQuestions is on a distinguished road
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
MrQuestions is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 19th, 2008, 08:10 PM   #2
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
Re: Simple SQL Select Query Question

I don't see what's the problem here??
Code:
"SELECT id FROM tags WHERE tagname = 'baseball'"
Did you try:
Code:
"SELECT * FROM tags WHERE tagname = 'baseball'"
What is your purpose of just querying the ID?
Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 19th, 2008, 10:35 PM   #3
New Member
 

Join Date: Mar 2008
Location: states
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 MrQuestions is on a distinguished road
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!
MrQuestions is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 19th, 2008, 10:43 PM   #4
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
Re: Simple SQL Select Query Question

Are you sure ID 11 has "baseball" as the current value?
Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 20th, 2008, 11:32 AM   #5
New Member
 

Join Date: Oct 2007
Location: Louth
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pagerss is on a distinguished road
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;
pagerss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 20th, 2008, 07:32 PM   #6
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
Re: Simple SQL Select Query Question

But he only want to select a field (tagname) with the value "baseball"?
Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 20th, 2008, 07:59 PM   #7
New Member
 

Join Date: Oct 2007
Location: Louth
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pagerss is on a distinguished road
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
pagerss is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old March 20th, 2008, 08:11 PM   #8
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
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...
Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help with (should be) simple count() query. MrQuestions Databases 2 March 23rd, 2008 05:42 PM
MYSQL/PHP Query question andrewlondon Databases 1 September 19th, 2007 07:26 AM
Simple CSS Question welshie HTML, XHTML and CSS 9 January 31st, 2007 08:22 AM
Query question - can I return values for records not found? Donny Bahama Databases 5 August 21st, 2006 07:39 AM
a simple question (I think) Colm Osiris HTML, XHTML and CSS 2 February 5th, 2006 05:17 AM


Search Engine Optimization by vBSEO 3.2.0 RC8