select pb.id,
p.name,
pb.batchName,
pb.batchCode,
s.detail,pb.program_id,
pb.session_id,
si.typeDescp,
si.id
from programBatch_info pb
join program p on pb.program_id=p.id
join session_info s on pb.session_id=s.id
join semester_info si on si.id=pb.semInfo_id
Here the name of first and last columns is 'id' so when I retrieve the values of this query first column object and last column object return the same value.But when I change the 'si.id' to 'pb.semInfo_id' the name of last column is'semInfo_id' and hence the correct values is retrieved. I tried this native query in hibernate platform.
Am I conceputally wrong or what is the actual case??
Not sure the question but try this:
select pb.id,
p.name,
pb.batchName,
pb.batchCode,
s.detail,pb.program_id,
pb.session_id,
si.typeDescp,
si.id as [si_id]
from programBatch_info pb
join program p on pb.program_id=p.id
join session_info s on pb.session_id=s.id
join semester_info si on si.id=pb.semInfo_id
This is the syntax to specify a new column name.
Related
I get the PropertyTypeName of an object using the following code,
typename = eaElement.PropertyTypeName
What would be the equivalent SQL query to get the same?
Tried looking up t_objectproperties,t_objects,t_attributes etc tables. Couldn't find what I am looking for
The PropertyTypeName of a property or Type is hidden in EA through the PDATA1 column.
That column contains the ea_guid of the type element.
select o.name as partName, ot.Name as TypeName
from t_object o
inner join t_object ot on ot.ea_guid = o.PDATA1
where o.ea_guid = '<replace by guid of part>'
This is my SQL query in text format:
SELECT sum(D.Kilogramos) as Kilogramos, C.Categoria , C.Tipo S Tipo, LA.Huerta,TC.TipoCorte, LA.JefeAcopio,LA.IdLote
FROM dbo.MOV_EmpaqueDetalle D
INNER JOIN dbo.Rep_Lote LA on LA.IdLote= D.IdLote
INNER JOIN dbo.MOV_OrdenesCorte MO on MO.IdOrdenCorte = LA.IdOrdenCorte
INNER JOIN dbo.PRO_Productos P on P.IdProducto=D.IdProducto
INNER JOIN dbo.PRO_Categorias C ON C.IdCategoria=P.IdCategoria
INNER JOIN dbo.MOV_Acuerdos A on A.IdAcuerdo=LA.IdAcuerdo
INNER JOIN dbo.MOV_TiposCorte TC on A.IdTipoCorte=TC.IdTipoCorte
WHERE CAST(MO.Fecha AS DATE) BETWEEN '2018-10-23' AND '2018-10-23'
GROUP BY LA.Huerta, LA.IdLote,C.Categoria, C.Tipo, TC.TipoCorte, LA.JefeAcopio,Mo.Fecha
ORDER BY LA.Huerta
The rows in the column kilogramos of the Huerta EL DOS are wrong, the information correct must be the following:
Kilogramos Huerta
13807.00 El DOS
I have got the accumulated row in sum function, the kilograms are wrong.
Its kind of hard to provide an answer with the few information you provided, but I would suggest to check whether your GROUP BY is correct.
If you really just need the sum Kilogramos over the different Huertas your group condition should look like this: GROUP BY LA.Huerta
I want to get student details from different tables with given academic year and class.
Query that i used is:
SELECT
list_acad_years.acad_year,
a.fk_stu_id,
tbl_stu_details.stu_fname,
tbl_stu_details.stu_sname,
a.fk_section_id,
b.fk_class_id,
list_class.class_name,
list_sections.section_code
FROM
tbl_stu_details,
list_class,
list_sections,
list_acad_years
INNER JOIN
tbl_stu_class AS a
ON
(
list_acad_years.pk_acad_year_id = a.fk_year_id
)
INNER JOIN
tbl_stu_class AS b
ON
(list_class.pk_class_id = b.fk_class_id)
WHERE
(
list_acad_years.acad_year = '2019'
) AND(list_class.class_name = '10')
it shows the following error:
#1054 - Unknown column 'list_class.pk_class_id' in 'on clause'
columns of my table are:
tbl_stu_class:
pk_stu_cls_id`, `fk_stu_id`, `fk_year_id`, `fk_class_id`, `fk_section_id`, `current_yr`
list_class:
`pk_class_id`, `class_name`, `class_code`, `fk_user_id`
list_sections:
pk_section_id`, `section_code`, `section_description`, `fk_user_id`
list_acad_years:
`pk_acad_year_id`, `acad_year`, `acad_year_code`, `fk_user_id`
tbl_stu_details:
`pk_stu_id`, `stu_id`, `username`, `stu_fname`, `stu_mname`, `stu_sname`
list_sections:
`pk_section_id`, `section_code`, `section_description`, `fk_user_id`
Why did it say unknown column when the column is present?
It would be great help if you can help me make this query better...
Thanks in advance.
Your problem is that you are using old-style joins. Period. To make matters worse, you are combining them with new style joins.
The names of the tables are not understood across commas. That limits the scope of the definitions.
You appear to know how to write JOINs correctly. So, just fix the FROM clause and your code should work.
Your Inner join will alway connect to the last table in from statement if you are using multiple FROM table.
I have just change the position of INNER JOIN
try this let me know if it works.
SELECT
list_acad_years.acad_year,
a.fk_stu_id,
tbl_stu_details.stu_fname,
tbl_stu_details.stu_sname,
a.fk_section_id,
b.fk_class_id,
list_class.class_name,
list_sections.section_code
FROM
tbl_stu_details,
list_class INNER JOIN
tbl_stu_class AS b
ON
(list_class.pk_class_id = b.fk_class_id),
list_sections,
list_acad_years
INNER JOIN
tbl_stu_class AS a
ON
(
list_acad_years.pk_acad_year_id = a.fk_year_id
)
WHERE
(
list_acad_years.acad_year = '2019'
) AND(list_class.class_name = '10')
In an iReport I'm using parameter in SQL query, but the parameter field is not showing in the data set. I have a fee structure table which 12 months columns for amount, I'm trying to get the desire month by passing the parameter as column, but the parameter column is not showing in the data field. Here is my query, I'm passing FeeStructure.$P!{Months} as a parameter column.
SELECT
StudentInformation.ID, ClassS.Class, Parents.Parents,
FeeCatagory.FeeCatagory, FeeStructure.$P!{Months}
FROM
StudentInformation
INNER JOIN
ClassS ON StudentInformation.[C/Class] = ClassS.Id
INNER JOIN
Parents ON StudentInformation.ParentID = Parents.ID
INNER JOIN
FeeStructure ON ClassS.Id = FeeStructure.ClassID AND Parents.ID = FeeStructure.ParentID
INNER JOIN
FeeCatagory ON FeeStructure.CatagoryID = FeeCatagory.ID
WHERE
Class = $P{ClassID}
AND Parents = $P{Parent}
AND StudentInformation.ID = $P{StudentID}
ORDER BY
FeeCatagory
plz check with this.
$P!{Months} for this parameter give any month name as default value
and also use aliasing
FeeStructure.$P!{Months} as month
instead of
FeeStructure.$P!{Months}
its Access database..
i have a Library table, where Autnm Topic Size Cover Lang are foreign keys
each record is actually a book which has its properties such as author and stuff. i am not quite sure i am even using the correct JOIN.. quite new with "complex" SQL :)
SELECT Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
Library.ISBN, Library.Pages, Library.PUSD, Author.ID AS [AuthorID],
Author.Author_hebrew AS [AuthorHebrew],
Author.Author_English AS [AuthorEnglish],
Author.Author_Russian AS [AuthorRussian], Topic.ID AS [TopicID],
Topic.Topic_Hebrew AS [TopicHebrew], Topic.Topic_English AS [TopicEnglish],
Topic.Topic_Russian AS [TopicRussian], Size.Size AS [Size],
Cover.ID AS [CoverID], Cover.Cvrtyp_Hebrew AS [CoverHebrew],
Cover.Cvrtyp_English AS [CoverEnglish], Cover.Cvrtyp_Russian AS [CoverRussian],
Lang.ID AS [LangID], Lang.Lang_Hebrew AS [LangHebrew],
Lang.Lang_English AS [LangEnglish],
FROM Library INNER JOIN Author ON Library.Autnm = Author.ID
INNER JOIN Topic ON Library.Topic = Topic.ID
INNER JOIN Size ON Library.Size = Size.ID
INNER JOIN Cover ON Library.Cover = Cover.ID
INNER JOIN Lang ON Library.Lang = Lang.ID
WHERE (TopicID=13 AND LangID=1) ORDER BY LangID ASC
Edit: After inserting the parantheses #Guffa suggested, I got a new error:
Too few parameters. Expected 3.
In Access you need parentheses if you have more than one join. Also, as Ivar pointed out, you have an extra comma after the last item in the field list.
select
Library.Bknm_Hebrew, Library.Bknm_English, Library.Bknm_Russian, Library.Note,
Library.ISBN, Library.Pages, Library.PUSD, Author.ID as [AuthorID],
Author.Author_hebrew as [AuthorHebrew], Author.Author_English as [AuthorEnglish],
Author.Author_Russian as [AuthorRussian], Topic.ID as [TopicID],
Topic.Topic_Hebrew as [TopicHebrew], Topic.Topic_English as [TopicEnglish],
Topic.Topic_Russian as [TopicRussian], Size.Size as [Size], Cover.ID as [CoverID],
Cover.Cvrtyp_Hebrew as [CoverHebrew], Cover.Cvrtyp_English as [CoverEnglish],
Cover.Cvrtyp_Russian as [CoverRussian], Lang.ID as [LangID],
Lang.Lang_Hebrew as [LangHebrew], Lang.Lang_English as [LangEnglish]
from
(((((Library
inner join Author on Library.Autnm = Author.ID)
inner join Topic on Library.Topic = Topic.ID)
inner join Size on Library.Size = Size.ID)
inner join Cover on Library.Cover = Cover.ID)
inner join Lang on Library.Lang = Lang.ID)
Edit:
The error message "Too few parameters." means that you have defined parameters in the query that is not sent along when it's executed. As you don't use any parameters in the query it means that you have spelled some names in the query wrong, so that it thinks that they are parameters instead.
I'm not too familiar with Access, and therefore not sure if it accepts this, but I would start by removing the last comma from the select list.
Lang.Lang_English AS [LangEnglish], => Lang.Lang_English AS [LangEnglish]