I have a table named student_table.
The table consists of three columns: s_id, s_rollnum, s_name.
I want to insert a new student to that table. While inserting, name should be sorted alphabetically and roll number also get sorted accordingly. Any idea?
You can sort column values alphabetically easily by $this->db->order_by();
According to your table columns:
(s_id, s_rollnum, s_name)
$this->db->order_by('s_name ASC', 's_rollnum ASC');
You can also do it in multiple statements
$this->db->order_by('s_name', 'ASC');
$this->db->order_by('s_rollnum', 'ASC');
More info in the official documentation
Related
I'm having trouble with dynamic table sorting. Im reading a table via a dynamic field symbol. How can I sort this table by a certain field of that table (after the select). I know for a fact that this field is in the table, but since its dynamic I can't simply use "sort table by field".'
What are the alternatives?
You can sort
FIELD-SYMBOL <product_list> TYPE STANDARD TABLE.
by a single column with
CONSTANTS category TYPE char30 VALUE 'CATEGORY'.
SORT <product_list> BY (category).
and by multiple columns with
DATA(category_and_price) = VALUE abap_sortorder_tab( ( name = 'CATEGORY' )
( name = 'PRICE'
descending = abap_true ) ).
SORT <product_list> BY (category_and_price).
as described in the ABAP Keyword Documentation article SORT itab.
$data['establishments2'] = Establishments::Join("establishment_categories",'establishment_categories.establishment_id','=','establishments.id')->where('establishments.city','LIKE',$location)->where('establishments.status',0)->whereIn('establishment_id',array($est_data))->get(array('establishments.*'));
this is controller condition.
I have two tables, in table1 i am matching id with table2 and then fetching data from table1, and in table2 i have multiple values of same id in table 1. i want to get data of table1 values only one time, but as i am hvg multiple data of same id in table2 , data is repeating multiple times, can anyone please tell me how to get data only one time wheater table2 having single value or multiple value of same id... thank you
you can do it by selecting the field name you desired
instead get all field from table establishments
$data['establishments2'] = Establishments::Join("establishment_categories",'establishment_categories.establishment_id','=','establishments.id')->where('establishments.city','LIKE',$location)->where('establishments.status',0)->whereIn('establishment_id',array($est_data))->get(array('establishments.*'));
you can select specific field from table establishments like
$data['establishments2'] = Establishments::Join("establishment_categories",'establishment_categories.establishment_id','=','establishments.id')->where('establishments.city','LIKE',$location)->where('establishments.status',0)->whereIn('establishment_id',array($est_data))->get('establishments.fieldName');
or you can also do
$data['establishments2'] = `Establishments::Join("establishment_categories",'establishment_categories.establishment_id','=','establishments.id')->where('establishments.city','LIKE',$location)->where('establishments.status',0)->whereIn('establishment_id',array($est_data))->select('establishments.fieldName')->get();`
With the following table definition:
CREATE TABLE device_by_create_date (
year int,
comm_nr text,
created_at timestamp,
PRIMARY KEY ((year, comm_nr), created_at)
) WITH CLUSTERING ORDER BY (created_at DESC)
Comm_nr is a unique identifier.
I would expect to see data ordered by created_at column, which is not the case when I add data.
Example entries:
Table CQL:
How can I issue select * from table; queries, which return data ordered by the created_at row?
TLDR: You need to create a new table.
Your partition key is (year, comm_nr). You're created_at key is ordered but it is ordered WITHIN that partition key. A query where SELECT * FROM table WHERE year=x AND comm_nr=y; will be ordered by created_at.
Additionally if instead of (year, comm_nr), created_at your key was instead year, comm_r, created_at even if your create table syntax only specifiied created_at as the having a clustering order, it would be created as WITH CLUSTERING ORDER BY (comm_nr DESC, created_at DESC). Data is sorted within SSTables by key from left to right.
The way to do this in true nosql fashion is to create a separate table where your key is instead year, created_at, comm_nr. You would write to both on user creation, but if you needed the answer for who created their account first you would instead query the new table.
I am using MS Access 2013 DB
I have two tables
Table1:
StartDate,EndDate, ID1, ID2,ProgramName, LanguageID,Language, Gender,CenterName,ZoneName
Table2
StartDate,EndDate, ID3,ProgramName, LanguageID,Language, Gender,CenterName,ZoneName
I want to join these two tables and remove duplicates by comparing the following columns from both tables
StartDate,EndDate,ProgramName, LanguageID,Language, Gender,CenterName,ZoneName
some data in the columns StartDate, EndDate have null values also. The resultant table should contain the following columns with no duplicate data
StartDate,EndDate, ID1, ID2,ID3,ProgramName, LanguageID,Language, Gender,CenterName,ZoneName
First you want create new table (other structer)
Second insert every record to new table all record where value from table1 and table2 are diffrent (without duplicate). Remember about check
In Hive, you can use a function named_struct in order to create a list of key value pairs; the keys are usually the column names and the values are the values in the corresponding column. For example,
$hive> select id, named_struct('foo', name, 'address', address) as list from users;
id list
1 {'foo':'Alice', 'address':'Wonderland'}
2 {'foo':'Bob', 'address':'Portland'}
...
However, in order to make the list, I needed to explicitly write each column name. Is there any way to avoid doing this with either named_struct or some other similar function?
I expect to be able to write something like (assuming users has only three columns).
$hive> select id, named_struct(*) as list from users;
Since you are using all columns you don't need a named_struct. Something like struct("*") will work.