There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell drive driver drivers email error ethernet excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem problems router slow sound startup trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Solved: Small SQL Issue


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
johnnyburst79's Avatar
Computer Specs
Distinguished Member with 4,562 posts.
 
Join Date: Aug 2005
Location: Austin, TX
Experience: In what? ;)
06-Aug-2007, 11:40 AM #1
Solved: Small SQL Issue
I'm trying to select two rows from two columns and while I can select the columns, the selection of multiple rows is not falling into place. I can pull one row into the report, but not two.

This is what I'm writing

SELECT name, number FROM table
WHERE name='variable1','variable2'

Something is occurring around the , between variable1 and variable2. I know I doing something wrong, but can't figure it out. I can pull variable1 by itself just fine.

The specific error is:
sql: errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'variable2' at line 2
number: 1064

Any ideas would be greatly appreciated. I tried searching and could not find an answer to this problem.
__________________
"No free man shall ever be debarred the use of arms."
-Thomas Jefferson
__________________

Please support me in my ride against Diabetes
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-Aug-2007, 01:51 PM #2
I think you would have to make that two separate statements.

http://www.faqs.org/docs/ppbook/x5802.htm
johnnyburst79's Avatar
Computer Specs
Distinguished Member with 4,562 posts.
 
Join Date: Aug 2005
Location: Austin, TX
Experience: In what? ;)
06-Aug-2007, 02:18 PM #3
Nope, tried that, and this is the error I get:

sql: errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT name, number FROM table WHERE name='variable2'' at line 4
number: 1064

Use of AND in WHERE name='variable1' AND 'variable2' removes the variables from the rows. The columns show, but the rows are missing.
__________________
"No free man shall ever be debarred the use of arms."
-Thomas Jefferson
__________________

Please support me in my ride against Diabetes

Last edited by johnnyburst79 : 06-Aug-2007 02:26 PM.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-Aug-2007, 02:27 PM #4
SELECT name, number FROM `table` WHERE name = var2
johnnyburst79's Avatar
Computer Specs
Distinguished Member with 4,562 posts.
 
Join Date: Aug 2005
Location: Austin, TX
Experience: In what? ;)
06-Aug-2007, 02:43 PM #5
That's what I wrote in there, same error.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-Aug-2007, 02:50 PM #6
Sorry:
SELECT FirstName, LastName FROM `person` WHERE FirstName = 'Peter'

I just tried that, worked fine.

What are you using for the queries?
johnnyburst79's Avatar
Computer Specs
Distinguished Member with 4,562 posts.
 
Join Date: Aug 2005
Location: Austin, TX
Experience: In what? ;)
06-Aug-2007, 03:05 PM #7
This is what worked for me:

SELECT name, number FROM table
WHERE name IN('var1', 'var2', 'var3')

Last edited by johnnyburst79 : 06-Aug-2007 03:24 PM.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-Aug-2007, 03:32 PM #8
One way:

select name, population FROM `bbc` where name = 'France';
select name, population FROM `bbc` where name = 'Germany';
select name, population FROM `bbc` where name = 'Italy';

Anther way:

select name, population FROM `bbc` where population > '57100000' AND population < '83500000' AND region = 'Europe' LIMIT 0,3



I think there is a way to do this. This is a bit weird.
__________________
Guys, please, this is free tech support, act accordingly.
johnnyburst79's Avatar
Computer Specs
Distinguished Member with 4,562 posts.
 
Join Date: Aug 2005
Location: Austin, TX
Experience: In what? ;)
06-Aug-2007, 03:37 PM #9
When I did what you had, this is what the script checker gave me in PostgreSQL: sql: errorERROR: syntax error at or near "`" at character 30
number: 7
sql: errorERROR: syntax error at or near "`" at character 30
number: 7
sql: errorERROR: syntax error at or near "`" at character 30
number: 7

In MySQL5, I got this:
name population
France 60700000
name population
Germany 82500000
name population
Italy 57200000

Using the script I posted above, it shows this:
name population
France 60700000
Germany 82500000
Italy 57200000
__________________
"No free man shall ever be debarred the use of arms."
-Thomas Jefferson
__________________

Please support me in my ride against Diabetes
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
06-Aug-2007, 03:47 PM #10
Yeah, the "Another way:" works correctly.

So IN was it.

Interesting.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:17 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.