How to Install Operating System ??Complete Guide Installing The Operating System

Displaying Data With Select Command – If in the previous tutorial we entered some data with the insert command in MySQL, this time we will Displaying Data With Select Command and still use the database in the previous tutorial.

There are several things that need to be known, the technique of displaying data with the select command has several methods, actually it depends on our needs, for example, want to display all data, or only specific, or data containing similar syllables, here we will discuss one by one method that is.

Before going forward, there are a number of articles that you might be looking for.

Read too :

How To Display Data With Command Select

What is Select in the database? Select is a command that is used to display data from a table that is in the database and can also be an expression. As the beginning, it was discussed that there are several methods that can be used but come back as needed, in this tutorial all will be discussed in each method because often these needs are actually most often used.

In the case that often happens is if a programmer only wants to display specific data, the way is to use the logic of expression, generally starting with WHERE then conditions such as AND, OR, LIKE, BETWEEN, IN, NOT IN, and so forth.

The following is the Select … pseudo-code command

SELECT field / * FROM table_name WHERE condition

The above command is only a pseudo-code and cannot be used, the author only assumes the command so that it can be imagined here. It should be noted that in this MySQL tutorial we have created a database named name_database and in that database customer tables are available with some data.

How to display all data with Select

If you want to display all the data in the table in MySQL, use the following command …

SELECT * FROM customer;

If it’s correct, it should look like the picture below …

Need to be reminded, in the customer table there are several fields, what if you only want to display one or two fields, it’s easy. Replace the symbol “*” (without quotation) with the name of the field you want to display, for example, if you only want to display the customer’s name :

SELECT name_ customer FROM customer;

Or more than one field, namely by using commas as separators …

SELECT id_customer, name_customer From customer;

How To Display Specific Data With Select

What do you mean by specific data? is if you want to display data only on certain lines. In this tutorial, for example, you only want to display data customer with the id_customer P0001, using the WHERE command …

SELECT * FROM customer WHERE id_customer = ‘P0001’;

If it’s correct it looks like the picture below.

In this case, you can also use expeditions such as AND, OR and so on.

How to Display Data Containing Certain Words

How do I display data that only has certain words with the Select command in MySQL? the author will explain in advance the intent of “certain words”, is if the data that appears only wants to contain the desired word, for example, the author will display customer data that only has an email with a domain name “domain” only.

SELECT * FROM customer WHERE email LIKE ‘% domain%’;

The above command will display data that only contains e-mail with the name “domain”, in the case in this tutorial coincidentally there are only two data by using an e-mail address with the same domain, then the two data appear.

In cases that often occur, the LIKE command is often used to do data searches based on words.

How to display data according to certain data

What we will discuss in this sub-tutorial means that if we only want to display data that only contains data that has been defined, namely with the IN and NOT IN commands, similar to AND and OR, IN and NOT IN can do it simultaneously. For example, we will only display data that has id_customer P0001 and P0002.

SELECT * FROM customer WHERE id_customer IN (‘P0001’, ‘P0002’);

Then the two data that appear are only those that have id_customer P0001 and P0002. Then what about NOT IN? NOT IN the opposite of IN, for example, if you only want to display data where id_customer is only P0002.

SELECT * FROM customer WHERE id_customer NOT IN (‘P0001’);

Then a data will appear that only displays data that is id_customer not on P0001, namely P0002.

How to display data with a range or distance

Another case that often occurs is if you want to display data with a certain date distance, or at a certain price distance. In this tutorial unfortunately in the customer table, we don’t use dates, but we can use id_customer, let’s just assume that the data we have is already large, for example, id_customer have arrived between P0001 to P0100, how do I display data with id_customer between P0001 and P0002? that is by using BETWEEN.

SELECT * FROM customer WHERE id_customer ‘P0001’ AND ‘P0002’;

Then it will get data that only displays id_customer from the distance between P0001 to P0002.

So the tutorial Displaying Data With Select Command, hopefully, it is useful.

Before proceeding, there are a number of articles that might be looking for.

Also read :

User Review
0 (0 votes)

Add a Comment

Your email address will not be published. Required fields are marked *