Select in two tables that contain the same field name?
I am developing a CMS using Joomla! In Joomla db, we have 2 tables:
+----------+
|Categories|
+----------+
id
title
...
+-------+
|Content|
+-------+
id
title
catid
...
I have a request below:
SqlQuery q = new Select("*")
//.Top("1")
.From(JosContent.Schema)
.InnerJoin(JosUser.IdColumn, JosContent.CreatedByColumn)
.InnerJoin(JosCategory.IdColumn, JosContent.CatidColumn)
.Where("catid").IsEqualTo(catId);
And in the ASPX page I am showing data like this:
Tite : <%# DataBinder.Eval(Container.DataItem, "title") %>
In category : <%# DataBinder.Eval(Container.DataItem, "title") %>
// Category tite not Content title, but ASP.NET think it is Content title :-(
Please help me fix this? How to distract from this?
Thanks a lot!
+1
a source to share
3 answers
In your choice, you could do as Alan said and then use AS to change what you refer to them as later. (I don't know ASP on purpose, I'm a PHP programmer, but I'm guessing it's pretty similar).
Sort of
SELECT *, Categories.title AS categoryTitle, Content.title AS contentTitle ... ...
And then you can refer to categoryTitle or contentTitle.
+1
a source to share
I finished it :)
SqlQuery q = new Select("*", "jos_Categories.title AS 'CatTitle'")
//Select("*", "CatTitle = jos_Categories.title")
//Select("*", "CatTitle = JosCategory.TitleColumn")
//.Top("1")
.From(JosContent.Schema)
.InnerJoin(JosUser.IdColumn, JosContent.CreatedByColumn)
.InnerJoin(JosCategory.IdColumn, JosContent.CatidColumn)
.Where("catid").IsEqualTo(catId);
Thanks ... google :-)
0
a source to share