0

I searched the best practice/way to select some rows from a SQL Server database.

The result should be a category + description and their seminars (titel, description, etc).

My query:

$bla = $db->query("
            SELECT area.ID, area.Name             // noname.Titel AS x
              FROM SeminarCategorys tblJoin, Categorys area, Seminars noname
             WHERE noname.ID = tblJoin.SeminarID
               AND area.ID = tblJoin.CategoryID  
             GROUP BY area.ID, area.Name
        ");

This was my basic idea, but i have no idea how to select the other rows from the table 'Seminars'

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What is the expected output and what are you getting? – Kyle Jul 16 '13 at 19:18
  • 1
    possible duplicate of [How can an SQL query return data from multiple tables](http://stackoverflow.com/questions/12475850/how-can-an-sql-query-return-data-from-multiple-tables) – Skyp Jul 16 '13 at 19:33

1 Answers1

0

I had to decipher your requirements but I think this is it.

$bla = $db->query("
             SELECT cats.ID AS 'CategoryID', cats.Name AS 'CategoryName', sems.ID AS 'SeminarID', sems.Title* AS 'SeminarTitle', sems.Description* AS 'SeminarDescription'
             FROM Seminars sems
             JOIN SeminarCategorys junctiontable ON sems.ID = junctiontable.SeminarID
             JOIN Categorys cats ON cats.ID = junctiontable.CategoryID
        ")

Asterisks are fields that potentially don't exist but have used as an example.

Malkin
  • 159
  • 2
  • 13