LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SQL - need some help, tnx (https://www.linuxquestions.org/questions/programming-9/sql-need-some-help-tnx-751276/)

ButterflyMelissa 08-30-2009 11:12 AM

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

Dan04 08-30-2009 12:26 PM

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;


ButterflyMelissa 08-30-2009 12:51 PM

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!

ButterflyMelissa 08-30-2009 01:57 PM

I tested this and it works like a charm!

Thanks!!

Thor


All times are GMT -5. The time now is 04:46 PM.