Link to home
Start Free TrialLog in
Avatar of sasha85
sasha85

asked on

order by with join

filed data in column "subid" look like this: 12132332-43234_solg.mod.de
i got 2 tables. "table1", "table2"

table1 got columns: "subid" "name"
table2 got columns: "subid" "time"

*in the sql, the time field set as text.

how can i print the names of subid's from table1 in order of the time in table2
(mysql)
?
SOLUTION
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sasha85
sasha85

ASKER

mysql="SELECT table1.name FROM table1 LEFT OUTER JOIN table2 ON table1.subid = table2.subid ORDER BY table2.time ASC"
i got syntax error, LEFT OUTER?
Remove OUTER from the statement.
Avatar of sasha85

ASKER

mysql="SELECT table1.name FROM table1 LEFT JOIN table2 ON table1.subid = table2.subid ORDER BY table2.time ASC"
like this? LEFT..ON..
yes, that should do it.
its left join.. on..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you want to show what T2.name are missing from Tabl1 as well?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If both tables have the same number of records, use:

mysql="SELECT T1.name FROM table1 T1 INNER JOIN table2 T2 ON T1.subid = T2.subid ORDER BY T2.time"

If Table1 has more records, use:

mysql="SELECT T1.name FROM table1 T1 LEFT JOIN table2 T2 ON T1.subid = T2.subid ORDER BY T2.time Where Not IsNull(T2.Name)"
Mike, shouldn't the WHERE clause precede the ORDER BY clause in ur 2nd query ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sasha85

ASKER

i am kind of lost here...
i can't know wich onw of the tables will have more records...
what i shell use than?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sasha85

ASKER

ok.ok:)
thank you all you gave me so much solutions i was shoked for a while...:)
all of them good once