Welcome, Guest. Please login or register.
Did you miss your activation email?
02/08/12, 08:35
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  MySQL, PostgreSQL, MS SQL, Access (Moderators: Flash-db, Musicman, Ronald Wernecke, Jorge Solis, Andries Seutens)
| | |-+  How to combine 3 tables by SQL?
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: How to combine 3 tables by SQL?  (Read 6169 times)
happy_karen
Server what's that
*
Posts: 17


View Profile
« on: 07/24/08, 05:28 »

Hello, I want to ask how to combing the following sql since there are 3 tables totally needed to join?

The tables are:
score
-fields are: scoreid, sid, case_no, effort, Time
weekt
-fields are: weekid, datefrom, dateto, case_no

One SQL:
SELECT * FROM score, weekt where weekt.weekid='1' and score.case_no=weekt.case_no order by score.sid, score.case_no, score.scoreid;

Another SQL:
select * from student where sid = 'FROM ONE SQL STATEMENT';

How to combine using JOIN??

Thanks a lot!!
Logged
happy_karen
Server what's that
*
Posts: 17


View Profile
« Reply #1 on: 07/24/08, 05:30 »

sorry, forget to explain more:

student table fields are:
sid, Name

thanks!
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #2 on: 10/01/08, 12:20 »

Ooops, miss this thread. Just in case you didn't solve, consider to have a common column in the tables you need to have a relationship

Jorge
Logged

Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6162


View Profile WWW Email
« Reply #3 on: 10/02/08, 00:23 »

you can use implicit outer join, or write the join, which matches best.

implicit would look like this:
Code:
SELECT * FROM student, score, weekt where student.sid=score.sid and score.case_no=weekt.case_no and weekt.weekid='1' order by score.sid, score.case_no, score.scoreid;

try it out with phpMyAdmin, before you use it in your code.

BTW: you should never use select * - better use explicit fieldlist.
Even when you are requesting all fields, performance will be much better.
And if you join tables, with * you receive all joined fields twice - once from one, and another time from the other table Wink - this does not realy make sense, just for saving a few seconds typing Wink
« Last Edit: 10/02/08, 00:31 by Ronald Wernecke » Logged

happy flashing
Cool
Ronald
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!