can l plz ask you something ... l hav a database with 4 tables i.e

User(fname, lname,email and userid ------primary key{userid} )

Exam( examid, examname-------primary Key{userid})

Exam_user(examid, userid------primary key{examid})

Exam_category(categoryid, categoryname----prmary key{categoryid})


HOW CAN YOU WRITE AN SQL QUERY THAT ALLOWS U TO CREATE/retrieve A NEW
TABLE WITH FIELDS;;;;

(fname, lname,email, userid,examid, examname,categoryname)

Recommended Answers

All 2 Replies

User(fname, lname,email and userid ------primary key{userid} )

Exam( examid, examname,categoriid-------primary Key{examid})

Exam_user(examid, userid------

Exam_category(categoryid, categoryname----prmary key{categoryid})

you can write:

select u.fname,u.lname,u.email,c.categoryname,e.examname from user as u,exam as e,exam user as eu,category as c where u.userid=eu.userid and eu.examid=e.examid and e.categoryid=c.categoryid;

the above is vary basic query, try inner joins to be more specific..
read joins tutorial in google..

It doesn't look like you posted your entire table structures, hence there is no reasonable way to know where Exam_category.categoryid joins to the three other tables.

I'd also like to know the conditions of your joins.
e.g.
Can a user take the same exam more than once. ( Fail, Fail, Pass etc.)
Can an exam have more than one category and if so how does this connection between exams and categories get made.

These questions will drastically affect the kind of joins that should be used.

Please post your entire sql structure for your tables.

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.