-   Programming (
-   -   SQL - need some help, tnx (

ButterflyMelissa 08-30-2009 11:12 AM

SQL - need some help, tnx

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

More info,

tables involved:


- ID int(5)
- condition int(5)
- level (5)

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


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!


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:


SELECT tblGauge.ID, tblConditions.description, tblGauge.level
FROM tblGauge LEFT JOIN tblConditions ON tblGauge.condition = tblConditions.ID;

ButterflyMelissa 08-30-2009 12:51 PM


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!


ButterflyMelissa 08-30-2009 01:57 PM

I tested this and it works like a charm!



All times are GMT -5. The time now is 12:04 AM.