Query for Searching the Name Alphabetically

MySQL query for alphabetical search

You can try:

SELECT * FROM `test_tbl` WHERE cus_name REGEXP '^[abc]';

It will list all rows where cus_name starts with either a, b or c.

The regex used is ^[abc]:

  • ^ : Is the start anchor
  • [..] : Is the character class. So [abc] matches either an a or a b or a c. It is equivalent to (a|b|c)

The regex you were using : ^[^a-z]+$

  • The first ^ is the start anchor.
  • [..] is character class.
  • The ^ inside the character class
    negates it. So [^abc] is any
    character other than the three
    listed.
  • + is the quantifier for one or
    more.
  • $ is the end anchor.

So effectively you are saying: give me all the rows where cus_name contains one or more letters which cannot be any of the lowercase letters.

MySQL - SELECT the name that comes first alphabetically

This is a simple aggegation:

SELECT continent, MIN(name) AS name
FROM world
GROUP BY continent
ORDER by continent

Mysql: Select all values alphabetically between two strings in a table

If you only want the ID's you need:

select id from myTable where name between 'beatrice' and 'tom' order by name;

SQL alphabetical query and display data from name column

MySQL example:

SELECT id, title, name, year FROM table ORDER BY name

ORDER BY can be used to sort.

If you only want to have names beginning with A, use LIKE:

SELECT id, title, name, year FROM table WHERE name LIKE 'A%'

How to get a by alphabetical order in the select column of sql query?

You require an ORDER BY clause at the end of your SQL query, to order the resultset by the column containing the brand name...

select * from zhaq_woocommerce_attribute_taxonomies where
attribute_name='brand' ORDER BY {column_to_order_by}

...simply replace {column_to_order_by} with the column name.

Android Room Database: How to query alphabetically by name?

Use the ORDER BY keyword.

"select * from Users ORDER BY name"

MySQL - List details of names which precede a a given name alphabetically (first name and last name separate)

WHERE last_name < 'Callaghan' OR (last_name = 'Callaghan' AND first_name < 'Harry')

The first name only matters if the last name matches exactly.

Can select next record alphabetically, but what happens when the record name is identical?

Try a condition like this:

WHERE `name` > (SELECT `name` FROM `names` WHERE `id` = X)
OR `name` = (SELECT `name` FROM `names` WHERE `id` = X) AND `id` > X

how to sort alphabetically with the same department

You may add a second level to the ORDER BY clause to fall back to sorting on the department name in the event that two or more department have the same location:

SELECT location_id, department_name
FROM Departments
ORDER BY location_id DESC, department_name;


Related Topics



Leave a reply



Submit