The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
select / 2tables using desc
Discuss select / 2tables using desc in the MySQL Help forum on Dev Shed. select / 2tables using desc MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 21st, 2000, 10:02 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hallo,
I'm from german, so I can't write english not verry well!
My problem is the follows:
There are two tables
both with an Column there are inside the same
the first one is a main table with entries like PersonalDB FirstName, LastName, Birthday aso...
the second one is a table "under" the main table with entries like PersonalDB EntryDate, Message, User, timestamp aso...
that means the second table has any entries wich will show if choose one entry from the first table. Understand me?
first table secon table
1. 1.1
2. 1.2
3. 1.3
2.1
2.2
3.1
3.2
...
Well, I'm looking for a posibility that you can see all entries of the first tables and the youngest data of the second table
LIKE:
first table second table
1. 1.3
2. 2.2
3. 3.2
Understand me? I hope so! And I need YOUR help!
Please help, if you can an send me an email or post your answer behind my posting!
Thanks a lot!
By,
Hannes
|

June 21st, 2000, 10:26 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I have used the follow select-statement:
SELECT rma.rmanr, geraet, verlauf.bearbeiter, verlauf.massnahme, verlauf.timestamp, verlauf.status
FROM rma, verlauf
WHERE rma.rmanr=verlauf.rmanr
ORDER BY verlauf.timestamp desc
this is a sort but it is not grouped!
If I grouped this I have got fals datas!
I have to have a statement wich will first order an after this the result has to group!
Thanks a lot!
|

June 22nd, 2000, 02:59 PM
|
|
Contributing User
|
|
Join Date: Mar 2000
Posts: 60
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
You write English better than I write German...
So, if I understand your question, you would like to do a JOIN of two tables based on a field that appears in both tables ("rmanr?").
As I just learned today, JOINs of this type aren't possible with MySQL 3.22. In Mysql 3.23, it is possible to create a TEMP table in which you can create all of the fields from both tables. It's a messy JOIN but it works.
If I am wrong, I would love to know how to do this more cleanly. Ideas?
|

June 22nd, 2000, 03:29 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Yes, joins are possible with 3.22.xx. I use joins constantly and normalization is quite useless without them.
Hannes,
You haven't said HOW you'd like the query grouped, and I don't see any functions in the query where a GROUP BY clause is going to be used.
I'm also curious as to WHY you need a join here since rmanr is the only column you are getting from table rma (unless geraet is from that table, it's lacking a table designator).
|

June 23rd, 2000, 02:05 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 5
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
My selct-Statement is the follows:
SELECT verlauf.RMANr,rma.geraet,verlauf.Bearbeiter,verlauf.Status,verlauf.TimeStamp
from rma,verlauf
where rma.rmanr=verlauf.rmanr and verlauf.status<>'geschlossen'
GROUP BY verlauf.RMANr
order by verlauf.rmanr, verlauf.timestamp";
The result isn't the right result!
Better use
first ORDER BY and then GROUP BY, but this is a false sql-statement - understand me!
The table "verlauf" will grow verry fast! So I think it is not a good idea using a TEMP TABLE!
looking forward to your answers!
Nice to received your messages!!!
Thanks a lot!
Hannes
|

June 23rd, 2000, 07:35 AM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
I still don't understand why you are using a GROUP BY clause. GROUP BY is used when you are using a function that would operate across several records (such as count(), avg(), min(), max(), etc) and you want to group the results by the value of another column. You are not using one so the GROUP BY should have no affect. The best I can understand from your explanation, this:
order by verlauf.rmanr, verlauf.timestamp
should be enough to do what you want.
|

June 23rd, 2000, 11:36 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
order by verlauf.rmanr, verlauf.timestamp
Actually that is enough for him to sort it in a proper way.
Hannes,,
see the mysql manual. their you can see some examples for group by and order by.
It has explained when you should use group by and order by clauses.
------------------
SR -
shiju.dreamcenter.net
"The fear of the LORD is the beginning of knowledge..."
[This message has been edited by Shiju Rajan (edited June 23, 2000).]
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|