Last post Jan 21, 2015 11:27 AM by xequence
Jan 19, 2015 08:37 PM|mdehghani|LINK
I used to have an exam-schedule Table including the following columns:
which I could easily generate a dynamic html table from it.. but then I realized that it needs normalization .. so I moved the item columns to a new table containing these columns:
Now, I wonder how I should combine the two tables to dynamically generate the former html table once again?
Jan 19, 2015 08:49 PM|wavemaster|LINK
You would need a column in exam-schedule that links to ItemId in the second table
ExamId, Title, Date, ItemId
ItemId, Item1.... Item6
select ExamId, Title, Date, Item1, Item2,.... Item6
from exame-schedule es
join items i on es.ItemId = i.ItemId
Jan 20, 2015 03:29 AM|ayanmesut|LINK
To combine two tables, you need to ave a COMMON FIELD in both tables. (ItemID)
Then you can combine and get the necessary fields from both tables using the SELECT command as wavemaster showed..
Jan 20, 2015 07:10 AM|mdehghani|LINK
I actually used this query using ExamId common field (sorry for the naming changes):
ON Exams.ExamId=Contents.ExamId ;
and i got sth like this result:
first exam some text
second exam some text
third exam some text
. . .
now I need to divide the columns to create a horizontal result like this
[Title] [Text] [Text] [Text] . . .
first exam some text some text some text . . .
second exam some text some text some text . . .
third exam some text some text some text . . .
should I use multiple joins for doing this?
Jan 20, 2015 10:05 AM|wavemaster|LINK
No need for multiple joins.
The relationships is not defined by what you have.
ExamId is the primary key for your Exams table, your Items table needs a primary key as well. We suggested ItemId.
Then you need an ItemId column in Exams
Jan 20, 2015 10:31 AM|ayanmesut|LINK
Show your loops please..
Jan 20, 2015 11:01 AM|mdehghani|LINK
sorry for not being accurate.. I have already added an ItemId column to the Exams Table as a FK. I just cant understand the right query..
Jan 20, 2015 11:03 AM|mdehghani|LINK
does the loops matter? I thought I should find the right query first then use a foreach loop to display the table
Jan 20, 2015 12:51 PM|wavemaster|LINK
Fix your tables and relationship first.
What is the latest query?
Jan 20, 2015 12:53 PM|mdehghani|LINK
haven't changed anything from the last descriptions..
Jan 20, 2015 02:05 PM|mdehghani|LINK
Jan 20, 2015 02:36 PM|wavemaster|LINK
SELECT Title, Text
FROM Exams e
JOIN Contents c ON e.ItemId = c.ItemId
Jan 20, 2015 02:48 PM|mdehghani|LINK
Sorry I think I made a mistake. i apologize .. I don't have an ItemId in the Exams table.. but why should I have one? every exam has several items .. can't give an itemId to an exam.. doesnt make sense.. Should I start a new thread and explain more accurate?
Jan 20, 2015 04:34 PM|mdehghani|LINK
i started a modified thread in sql forums
Jan 21, 2015 11:27 AM|Xequence|LINK
lazy loading vs eager loading vs deferred loading