I have an equipment database that contains three tables: name, equipment and equipmentacitiv ity. The equipments are assigned and unassigned as used and return. Thus, each equipment, unless it is new, has been assigned (A) and unassigned (U). However, I need the query to pull ONLY the current status of all the equipment.
Query to pull current status only.
Collapse
X
-
You will need to elaborate a bit more on your DB structure. You say you have three tables, but which one has the column current_status or whatever? Where/What do you assign (A) or (U) to?
The statement should be very simple:
Code:SELECT current_status FROM equipment
-
Hello TheServant - the assigned codes, A and U, are stored in the equipmentactivi ty table under the CODE column. The assigned code change from A to U everytime the equipment is assigned and unassigned. Each equipment has been assigned and unassigned several times so some has mutiple A and U. However, I only need the current client the equipment is Assigned to not the previous ones. I ran the query below but it is leaving some record out.
SELECT distinct c.name, a.code, x.SerialNumber, a.date
FROM client C, equipmentactivi ty a, equipment x
where C.ID = a.ID and x.EquipmentID = a. EquipmentID
Group by a.code,x.Serial Number;Comment
-
What is that returning, and what do you want it to return? You originally asked for a query to "pull ONLY the current status of all the equipment", but you seem to want a few other things, like names which are obviously stored in another table?
With regards to getting the current status (assigned, unassigned or never assigned), I would do that once you have the result instead of trying to do that with MySQL. If you're using PHP for example, it's quite easy to get the last character of a string, which sounds like it will be your current status.Comment
Comment