LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-30-2009, 11:12 AM   #1
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,189
Blog Entries: 23

Rep: Reputation: 278Reputation: 278Reputation: 278
SQL - need some help, tnx


Hi,

Short question : how do I replace a value (that is the ID of a message) in an SQL?

More info,

tables involved:

Quote:
tblGauge
- ID int(5)
- condition int(5)
- level (5)

tblConditions
- ID int(5)
- description varchar(50)
to call all the gauge readings, I'd use something like

Quote:
Select ID, condition, level from tblGauge order by level.
Whare tblConditions.ID has a one-to-many reation with tblGauge.condition.

If, in tblGauge, the condition is - say - 5, the 5 should be replaced with the fifth message (ie tblConditions.ID = 5) in tblConditions.

I _could_ run the SQL and then replace de integer value with a message for each line individually and then put the whole in the DefaultTableModel, but that is ... silly.

Can SQL do that for me? Yes! How? I dont know.
And direction is appreciated...

Tnx in advance!

Thor
 
Old 08-30-2009, 12:26 PM   #2
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Phrasing it as "replace a value" was confusing; at first I thought you were asking about the UPDATE statement.

If I understand correctly, you want:

Code:
SELECT tblGauge.ID, tblConditions.description, tblGauge.level
FROM tblGauge LEFT JOIN tblConditions ON tblGauge.condition = tblConditions.ID;
 
1 members found this post helpful.
Old 08-30-2009, 12:51 PM   #3
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,189
Blog Entries: 23

Original Poster
Rep: Reputation: 278Reputation: 278Reputation: 278
Hey!

That could be it! Joins (as in left join, inner and the like) always escaped me...

The result could then me something like:

1 severe 15
2 mild 5

where the tblConditions.ID as 15 would have "severe" as description and the one with 5 "mild"

Big-big tnx!

You've saved my Sunday here!

Thor!
 
Old 08-30-2009, 01:57 PM   #4
Thor_2.0
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,189
Blog Entries: 23

Original Poster
Rep: Reputation: 278Reputation: 278Reputation: 278
I tested this and it works like a charm!

Thanks!!

Thor
 
  


Reply

Tags
databases, sql


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
screen driver - some hlp pls...tnx Thor_2.0 Linux - Desktop 1 06-27-2009 08:28 AM
SQL noob question: can SQL effectively handle a 2D matrix? JoeyAdams Programming 2 03-17-2008 01:10 AM
LXer: Sql - stored procedures, views, and dynamic sql generation LXer Syndicated Linux News 0 08-17-2006 06:33 AM
SQL: old sql dump not loading into new db BrianK Linux - Software 1 07-25-2006 11:55 PM
cant run startx... pls help... tnx in advance kublador Linux - Newbie 1 08-16-2002 04:13 PM


All times are GMT -5. The time now is 09:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration