logo
Tags down

shadow

How to take some rows in the manual order and then rest in the regular way


By : Priti Punia
Date : October 14 2020, 02:21 PM
will be helpful for those in need I'm getting countries from database and would like to put some of them to the beginning by hand. The list should looks this way: , You can use a case expression:
code :
select t.*
from t
order by (case when col = 'Y' then 1
            when col = 'X' then 2
            when col = 'R' then 3
            else 4
       end),
      col;


Share : facebook icon twitter icon

MySQL Regular Expression to match multiple CSV rows containing certain fields in order


By : Varad Venkata Krishn
Date : March 29 2020, 07:55 AM
like below fixes the issue I'd like to use MySQL's REGEXP to match multiple numbers of a csv in a MySQL query. , MySQL
Since we're using MySQL REGEXP, we can take this approach:
code :
SELECT * FROM table WHERE field REGEXP '[[:<:]]2[[:>:]].*[[:<:]]9[[:>:]]'
1,2,3,4,5,6,7,8,9,10
2,9,1,2,3,4,5,10
1,2,3,5,9
9,2,3,4,5,10
2,1,2,3,4,5,10
20,9,1,2,3,4,5,10
2,19,1,2,3,4,5,10
mysql> SELECT * FROM test WHERE csv REGEXP '[[:<:]]2[[:>:]].*[[:<:]]9[[:>:]]';
+----+----------------------+
| id | csv                  |
+----+----------------------+
|  1 | 1,2,3,4,5,6,7,8,9,10 |
+----+----------------------+
1 row in set (0.00 sec)
^.*\b2\b.*\b9\b.*$
preg_match('/^.*\b2\b.*\b9\b.*$/', $csvRow);
preg_match('/^.*\b2\b.*\b9\b.*$/mg', $wholeCsvFile);

How to get rows in reversed order in HBase REST curl


By : Entercyber
Date : March 29 2020, 07:55 AM
hope this fix your issue Looks like it wasn't implemented in older versions but patch is available.
Here is the related JIRA ticket

MySQL Order by matching rows in First Table then rest


By : Namitha Raju
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , As mentioned by @Barmar, first fetch the rows having matched City names, and then create a UNION with rows having Neighbourhood for matched City names. Add relevant logic to ignore the columns having NULL value:
code :
Select 
CITY.ID, 
CITY.SLUG as CITY_SLUG,  
NEIGHBORHOOD.NAME as BAIRRO, 
NULL,
NULL,
NULL,
NULL
from CITY
LEFT OUTER join STATE on CITY.ID_STATE=STATE.ID
LEFT OUTER join NEIGHBORHOOD on NEIGHBORHOOD.ID_CITY = CITY.ID
WHERE (CITY.NAME LIKE '%PORTO ALE%' )
UNION
Select 
CITY.ID, 
CITY.SLUG as CITY_SLUG,  
NEIGHBORHOOD.NAME as BAIRRO, 
NEIGHBORHOOD.SLUG AS NEIGHBORHOOD_BAIRRO, 
CITY.NAME as CIDADE,  
STATE.ABB AS UF,  
STATE.SLUG AS STATE_SLUG  
from CITY
LEFT OUTER join STATE on CITY.ID_STATE=STATE.ID
LEFT OUTER join NEIGHBORHOOD on NEIGHBORHOOD.ID_CITY = CITY.ID
WHERE (CITY.NAME LIKE '%PORTO ALE%' )

SQLITE: How to get One row from table + get rest of rows in different order


By : Tony G
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a table with below rows. , If you wanted to do this only in the order by:
code :
order by (case when type = 'A' and
                    value = (select max(t2.value) from t t2 where t2.type = 'A')
               then 1 else 2
          end),
         value desc;
select t.*
from t cross join
     (select max(value) as maxvalue from t where type = 'A'
     ) ta
order by (case when t.type = 'A' and t.value = ta.maxvalue then 1 else 2 end),
         value desc;

How to show specific 2 rows at the top without order and then sort the rest by order using SQL DISTINCT, UNION


By : ArtVC
Date : March 29 2020, 07:55 AM
hop of those help? There is absolutely no guaranteed order of the returned result, unless order by is specified. Even if you find a query, that returned the rows in the desired order, on next run, tomorrow, or at client's site, it will not return them in the same order. So you must add an order by clause. You need to sort on some artificial values, like this:
code :
declare  @country table(id int , name varchar(50));                      
insert into @country (id, name) values( 1, 'Kuwait');                
insert into @country (id, name) values( 2, 'Australia');             
insert into @country (id, name) values( 3, 'Canada');
insert into @country (id, name) values( 4, 'spain');
insert into @country (id, name) values( 5, 'Turkey'); 
insert into @country (id, name) values( 6, 'Ireland');
insert into @country (id, name) values( 7, 'England');
insert into @country (id, name) values( 1, 'Kuwait');                
insert into @country (id, name) values( 2, 'Australia');             
insert into @country (id, name) values( 3, 'Canada');
insert into @country (id, name) values( 4, 'spain');
insert into @country (id, name) values( 5, 'Turkey'); 
insert into @country (id, name) values( 6, 'Ireland');
insert into @country (id, name) values( 7, 'England');

select id, name from (
select distinct id, name
from @country) t
order by case name when 'Ireland' then 'aaaaaaaaaaaaaaaaaaaaaaaa1' when 'England' then 'aaaaaaaaaaaaaaaaaaaaaaaa2' else name end
Related Posts Related Posts :
  • Query Finding Duplicate Values in one table
  • Create a user defined function that works with GROUP BY in mysql
  • Faster process for large insert
  • Unable to configure mysql database, after cloud sql proxy setup
  • (Amazon Linux) MySQL stops working on EC2 reboot
  • SQL procedure for inserting records in a table based on records in another table
  • How to name SQL FOREIGN KEY Constraint on CREATE two tables columns into a relationship TABLE
  • Sum, Subtract and Join of multiple mysql table columns
  • calculate standard deviation inside pivot table
  • Docker - mysqld: Table 'mysql.plugin' doesn't exist
  • Determine max number of overlapping DATETIME ranges
  • Puppet: file_line evaluates os.path.join
  • Insert data into blog in WordPress by Json link
  • filter all two tables to get all the data
  • MySQL SUBSTRING() with non-utf8 encoding
  • How to dump and download mysql from Google Clould's VM
  • List of items using count and average in MYSQL Workbench producing too few results
  • Add int to date SQL
  • MySQL - Find the lowest unique value in table
  • How to apply case when with if condition in MySql
  • SQL Count valid Transactions per User
  • Check if date colum is in some period which depends on another date column
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org