954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

DATABASE Query STATEMENT

hi all
i am a newbie want to know how to get values from two tables in database. I hae two tables one is the personla information and the other table is the salary table .Both tables have id number which may join them to gather. But what i need to do is, i need to retrieve only people who have a salary of 2500. Is it possible. i have tried below but it does not work can tell me where i went wrong

select name,position,age,salary
FROM personalinformation, salarydetails
WHERE personalinformation.id = salarydetails.id
AND salarydetails.salary = 2500


PLease help. Thanks in advance

newbie_here
Newbie Poster
11 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

whats the error you encountered? can you explain. than may be some good result generate for you from others

aqee_se
Newbie Poster
8 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

You need to store the personalinformation.id in salarydetails table. after that you need to link the personalinformation.id ane the personalinformation.id stored in salarydetails table.

tmani_85
Newbie Poster
14 posts since Feb 2009
Reputation Points: 10
Solved Threads: 2
 

For sure, they got error: ambiguity error, maybe the two tables have some same columns name, I see the syntax is correct.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

Thanks all it worked...so my next step is that i need to save it in a new database table i created in the same database (access).... is it possible?

thanks a lot in advance

cheers
newbie

newbie_here
Newbie Poster
11 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
INSERT INTO newtable AS (select personalinformation.name,personalinformation.position,personalinformation.age,salarydetails.salary
FROM personalinformation, salarydetails
WHERE personalinformation.id = salarydetails.id
AND salarydetails.salary = 2500)


but the porblem i encounter is that it says that INSERT INTO syntax error. Can anyone help please

thanks in advance

cheers
newbie

newbie_here
Newbie Poster
11 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 
INSERT INTO newtable(name,position,age,salary) values AS (select personalinformation.name,personalinformation.position,personalinformation.age,salarydetails.salary
FROM personalinformation, salarydetails
WHERE personalinformation.id = salarydetails.id
AND salarydetails.salary = 2500)


but the porblem i encounter is that it says that INSERT INTO syntax error. Can anyone help please

thanks in advance

cheers
newbie

newbie_here
Newbie Poster
11 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Give us your code, we can't work with prediction!

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

i have pasted the code above already bro.....Because i need to save the values in a different table within the database. so i have a table called details. so i need to put all these generated values from the two tables into this table. when i tried compiling i get this error. invalid syntax.......attached down is my query string to place the values in another table. ihope this info issufficient ..... please help

Dim myQuery as String = " INSERT INTO details(name,position,age,salary) values AS (select personalinformation.name,personalinformation.position,personalinformation.age,salarydetails.salary FROM personalinformation, salarydetails WHERE personalinformation.id = salarydetails.id AND salarydetails.salary = 2500)"
newbie_here
Newbie Poster
11 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

If you run it against SQL Server or MS Access take this statement and run it there, see if there's error or not.

Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You