It varies by state. Here’s how it works in New York:
Each county has a “District Attorney.” He or she is an elected official responsible for prosecuting crimes in the county. Most often, the prosecution of individual cases is handled by Assistant District Attorneys hired and supervised by the DA. In Law and Order, Steven Hill played Adam Schiff, who was the DA for New York County (Manhattan), and Sam Waterston, Michael Moriarty, Jill Hennessy, and Carey Lowell, among others played ADAs (though I think Sam Waterston became DA in the last few seasons). In some states, like Maryland and Illinois, the county prosecutor is called the State Attorney, which is the equivalent to the District Attorney in New York.
The Attorney General is a statewide elected official, who is responsible representing the state in all legal matters, and who is assisted by Assistant Attorney Generals. The AG is mostly responsible for civil litigation involving the state, but also prosecutes a limited number of crimes. She has a Deputy Attorney General, Assistant Attorney Generals, a Solicitor General and a whole host of other attorneys in her department, the most senior of which are Presidentially appointed with Senate consent.
Each county has an appointed county attorney, who represents the county in civil litigation. Similarly, most municipalities (cities, towns, villages) have an attorney that represents it in civil litigation, which may be known as the Town Attorney, etc., but in the case of New York City and some other cities, known as the Corporation Counsel. Depending on the size of the municipality, these may be full-time municipal employees, or part-timers, and may have one or more (in the case of New York City, hundreds) of assistants.
There is also the federal system. At the top is the Attorney General, currently Loretta Lynch, who is appointed by the President with Senate consent. She is the chief official responsible for federal law enforcement, and oversees the FBI, DEA and a whole range of other agencies.
Each state has one or more judicial districts/District Courts (e.g. New Jersey has one district the District of New Jersey, while New York has four, the Southern, Eastern, Northern and Western Districts of New York). Each judicial district has a U.S. Attorney, appointed by the President with Senate consent, and assisted by Assistant U.S. Attorneys (AUSAs). Before she was AG, Loretta Lynch was US Attorney for the Eastern District of New York (covering Brooklyn, Queens and Long Island). The US Attorney for each district prosecutes federal crimes and represents the federal government in his or her district, though sometimes Assistant Attorneys General and lawyers for federal agencies are involved.