Simple SQL Select Query Question

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 19th, 2008, 21:52
New Member
Join Date: Mar 2008
Location: states
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote

  #2 (permalink)  
Old Mar 19th, 2008, 23:10
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Simple SQL Select Query Question

I don't see what's the problem here??
Code: Select all
"SELECT id FROM tags WHERE tagname = 'baseball'"
Did you try:
Code: Select all
"SELECT * FROM tags WHERE tagname = 'baseball'"
What is your purpose of just querying the ID?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Reply With Quote
  #3 (permalink)  
Old Mar 20th, 2008, 01:35
New Member
Join Date: Mar 2008
Location: states
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
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!
Reply With Quote
  #4 (permalink)  
Old Mar 20th, 2008, 01:43
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
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)
Reply With Quote
  #5 (permalink)  
Old Mar 20th, 2008, 14:32
Junior Member
Join Date: Oct 2007
Location: Louth
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
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;
Reply With Quote
  #6 (permalink)  
Old Mar 20th, 2008, 22:32
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
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)
Reply With Quote
  #7 (permalink)  
Old Mar 20th, 2008, 22:59
Junior Member
Join Date: Oct 2007
Location: Louth
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #8 (permalink)  
Old Mar 20th, 2008, 23:11
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
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)
Reply With Quote
Reply

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 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


All times are GMT. The time now is 10:00.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43