February 02, 2016

Hibernate - selecting multiple rows in a single query



/*
SQLyog Community Edition- MySQL GUI
MySQL - 5.1.32-community
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `tbl_dcs` (
`columnA` varchar (30),
`columnB` varchar (30)
);
insert into `tbl_dcs` (`columnA`, `columnB`) values('1','11');
insert into `tbl_dcs` (`columnA`, `columnB`) values('2','22');
insert into `tbl_dcs` (`columnA`, `columnB`) values('3','33');


Queries

select * from cfed_sample.tbl_dcs order by columnA;


select columnA,group_concat(columnB) from cfed_sample.tbl_dcs group by columnA;

@OrderBy(clause = "NAME DESC")
Set<Foo> fooList = new HashSet();

String hql = "FROM Foo f ORDER BY f.name";
Query query = sess.createQuery(hql);


other options

/*
SQLyog Community Edition- MySQL GUI
MySQL - 5.1.32-community
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;

create table `dcs_hotels` (
`Book_date` date ,
`Avail_hotel` double
);
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','4');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','3');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','5');
insert into `dcs_hotels` (`Book_date`, `Avail_hotel`) values('0000-00-00','1');


select Book_date,group_concat(Avail_hotel) from cfed_sample.dcs_hotels group by Book_date;



http://javabelazy.blogspot.in/

Facebook comments