hi all,
I need to join three tables
my tables are

___________
markmaster
___________
stuid
subid
examcode
mark
___________
_____________
subjectmaster
_____________
subid
subname
subtype
externalmark
internalmark
_____________
___________
exammaster
___________
examcode
examname
duration
description
____________

I need result like stuid,subname,subtype,examname,mark . Could any one guide to write query for that
Thanks in advance

Recommended Answers

All 4 Replies

Whenever you need to join tables you use the JOIN command and then specifiy which columns in the joined table form the linkage (are the same).
For your tablesto get stuid and subname the query would be:

SELECT mm.stuid, sm.subname FROM markmaster AS mm JOIN subjectmaster AS sm ON mm.subid = ms.subid;

The AS command lets you give shorter aliases to a table if you didn't already know. And you can specify a WHERE clause on the end if you need to. You should be able to add in the exammaster table from there, just use another JOIN and ON statement.

commented: Short and sweet and a good example. +9

thanks for your reply hericles,
I know about join operations I don't know how to join 3 tables,
I need stuid from markmaster ,subname from subjectmaster ,subtype from subjectmaster ,examname from exam master ,mark from markmaster .
could you tel me how can I achieve that ..

To JOIN a third table just add another 'JOIN tableName' and another 'ON...'

SELECT mm.stuid, mm.mark, sm.subname, sm.subtype, em.examname FROM subjectmaster AS sm JOIN markmaster AS mm ON sm.subid = mm.subid JOIN exammaster AS em  ON sm.examcode = em.examcode;

thanks hericles

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.