Web Design and Development Forums

Simple SQL Select Query Question

This is a discussion on "Simple SQL Select Query Question" within the MySQL section. This forum, and the thread "Simple SQL Select Query Question are both part of the Databases category.


Go Back   Webforumz.com > Databases > MySQL

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Mar 19th, 2008, 21:52   #1 (permalink)
New Member
 
Join Date: Mar 2008
Location: states
Posts: 9
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 Mar 19th, 2008, 23:10   #2 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,565
Blog Entries: 2
Send a message via Yahoo to Monie
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?
__________________

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 Mar 20th, 2008, 01:35   #3 (permalink)
New Member
 
Join Date: Mar 2008
Location: states
Posts: 9
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 Mar 20th, 2008, 01:43   #4 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,565
Blog Entries: 2
Send a message via Yahoo to Monie
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 Mar 20th, 2008, 14:32   #5 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: Louth
Posts: 26
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.com - news and blog reader
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 Mar 20th, 2008, 22:32   #6 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,565
Blog Entries: 2
Send a message via Yahoo to Monie
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 Mar 20th, 2008, 22:59   #7 (permalink)
Junior Member
 
Join Date: Oct 2007
Location: Louth
Posts: 26
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.com - news and blog reader
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 Mar 20th, 2008, 23:11   #8 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,565
Blog Entries: 2
Send a message via Yahoo to Monie
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

Thread Tools
Rate This Thread
Rate This Thread:

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
hopefully a simple question newoptical Hosting & Domains 9 Sep 21st, 2007 22:02
MYSQL/PHP Query question andrewlondon MySQL 1 Sep 19th, 2007 11:26
simple question Daniel HTML Forum 29 Feb 6th, 2007 17:23
Simple CSS Question welshie CSS Forum 9 Jan 31st, 2007 12:22
Query question - can I return values for records not found? Donny Bahama MSSQL & Access 5 Aug 21st, 2006 11:39



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 17:27.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59