Hi Guys, I have 4 tables, viz. problem, area, engineer and complaints. While storing the data in the table of complaints, the respective ids of former three are stored. While displayng the records of complaints, i am able to get the ids of the former tables viz. problem, area and engineer and not the names. The other fiels are displayed, fine. My problem is how do I run a SQL query, such a way that I get the names of the above mentioned tables. The tables are as follows: 1)probelm : probid, name. 2)area : areaid, name. 3)engineer: engid, engineer. 4)complaints: compid,custname,date,time,problem,area,engineer,status. Pls help me !
Is this what you meant? A join? Note: "problemname" and "areaname" are field aliases for your result set, because both fields originally have the same name "name". A few comments though. Two fundamentally different types of things should, if at all possible, not have the same name. So, "problem.name" and "area.name" are fine, they refer to a similar things in different tables. But "engineer.engineer" and "complaints.engineer" are very different! The first is a name, the second is an id field. Try to adopt a naming convention for your id fields and others instead. For example:
problem: id, name
area: id, name
engineer: id, name
complaints: id, problemid, areaid, engineerid,...
Some people don't like things like "id" and "name" in tables, and would want you to use "problem_id" and "problem_name". That's fine too. As long as you're consistent. Furthermore, watch out with names like "date", "time", and perhaps also "status". In some databases they are reserved words, and to prevent problems you would always have to quote these field names (which leads you straight into the snake pit of case sensitivity if you don't watch out). Rather avoid them if you can. - Peter