MEM
MEM

Reputation: 31347

mysql - query example request

Updated

Hello all,

MySQL here.

Let's say we have 3 tables.

TableA, TableB, TableC.

TableB relates with foreign keys, TableA and TableC.

I would like to: List some data from TableA and TableC BUT, that data should be ordered by some column of TableB.

Can I have an example of the above so that I can study it and try to transform to my needs?

Thanks a lot. MEM

Upvotes: 0

Views: 348

Answers (3)

DwB
DwB

Reputation: 38320

select
    tA.blah,
    tA.goop,
    tC.schmarr,
    tC.broigle
from
    tB
        join tA on tA.joincol1 = tB.joinCol1
        join tC on tC.joinColx = tB.joinColx
order by
    tc.schmarr

Upvotes: 0

Vadyus
Vadyus

Reputation: 1329

mysql allows you to order by colums that not selected, so you can join your tables
select ta.somefield, tc.somefield
from TableA ta INNER JOIN TableC tc on tc.somefield=ta.somefield
INNER JOIN TableB tb on tb.somefield=ta.somefield
ORDER by tb.somefield

Upvotes: 1

Maximus
Maximus

Reputation: 2976

SELECT TABLEA.fieldnames, TABLEC.fieldnames FROM TABLEA, TABLEB, TABLEC WHERE TABLEA.PRIMARY=TABLEB.TABLEA_PRIMARY AND TABLEC.PRIMARY=TABLEB.TABLEC_PRIMARY ORDER BY TABLEC.fieldname DESC

Upvotes: 0

Related Questions