SQL Queries

12 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.73
List Price:  €65.43
You save:  €18.69
£39.55
List Price:  £55.38
You save:  £15.82
CA$68.39
List Price:  CA$95.75
You save:  CA$27.36
A$76.50
List Price:  A$107.11
You save:  A$30.60
S$68.11
List Price:  S$95.36
You save:  S$27.25
HK$391.33
List Price:  HK$547.90
You save:  HK$156.56
CHF 45.19
List Price:  CHF 63.27
You save:  CHF 18.08
NOK kr551.82
List Price:  NOK kr772.60
You save:  NOK kr220.77
DKK kr348.47
List Price:  DKK kr487.88
You save:  DKK kr139.41
NZ$84.17
List Price:  NZ$117.84
You save:  NZ$33.67
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,499.99
List Price:  ৳7,700.43
You save:  ৳2,200.43
₹4,169.28
List Price:  ₹5,837.33
You save:  ₹1,668.04
RM238.32
List Price:  RM333.67
You save:  RM95.35
₦66,060.50
List Price:  ₦92,489.99
You save:  ₦26,429.48
₨13,951.51
List Price:  ₨19,533.24
You save:  ₨5,581.72
฿1,848.80
List Price:  ฿2,588.46
You save:  ฿739.66
₺1,625.07
List Price:  ₺2,275.23
You save:  ₺650.15
B$255.76
List Price:  B$358.08
You save:  B$102.32
R938.81
List Price:  R1,314.42
You save:  R375.60
Лв91.38
List Price:  Лв127.95
You save:  Лв36.56
₩68,890.62
List Price:  ₩96,452.39
You save:  ₩27,561.76
₪190.87
List Price:  ₪267.23
You save:  ₪76.36
₱2,881.72
List Price:  ₱4,034.64
You save:  ₱1,152.92
¥7,903.16
List Price:  ¥11,065.06
You save:  ¥3,161.90
MX$857.83
List Price:  MX$1,201.03
You save:  MX$343.20
QR182.72
List Price:  QR255.83
You save:  QR73.10
P689.81
List Price:  P965.79
You save:  P275.98
KSh6,639.79
List Price:  KSh9,296.24
You save:  KSh2,656.45
E£2,392.59
List Price:  E£3,349.82
You save:  E£957.23
ብር2,876.01
List Price:  ብር4,026.64
You save:  ብር1,150.63
Kz41,694.65
List Price:  Kz58,375.85
You save:  Kz16,681.20
CLP$47,588.94
List Price:  CLP$66,628.33
You save:  CLP$19,039.38
CN¥362.20
List Price:  CN¥507.11
You save:  CN¥144.91
RD$2,937.78
List Price:  RD$4,113.13
You save:  RD$1,175.34
DA6,709.29
List Price:  DA9,393.54
You save:  DA2,684.25
FJ$113.10
List Price:  FJ$158.35
You save:  FJ$45.25
Q389.77
List Price:  Q545.71
You save:  Q155.94
GY$10,484.28
List Price:  GY$14,678.83
You save:  GY$4,194.55
ISK kr7,005.56
List Price:  ISK kr9,808.34
You save:  ISK kr2,802.78
DH506.20
List Price:  DH708.72
You save:  DH202.52
L888.32
List Price:  L1,243.72
You save:  L355.39
ден2,874.95
List Price:  ден4,025.16
You save:  ден1,150.21
MOP$404.09
List Price:  MOP$565.76
You save:  MOP$161.67
N$945.52
List Price:  N$1,323.80
You save:  N$378.28
C$1,844.23
List Price:  C$2,582.07
You save:  C$737.84
रु6,681.04
List Price:  रु9,353.99
You save:  रु2,672.95
S/188.25
List Price:  S/263.57
You save:  S/75.31
K193.43
List Price:  K270.82
You save:  K77.39
SAR187.48
List Price:  SAR262.49
You save:  SAR75
ZK1,328
List Price:  ZK1,859.31
You save:  ZK531.30
L232.80
List Price:  L325.94
You save:  L93.14
Kč1,174.50
List Price:  Kč1,644.39
You save:  Kč469.89
Ft18,330.20
List Price:  Ft25,663.75
You save:  Ft7,333.54
SEK kr544.35
List Price:  SEK kr762.14
You save:  SEK kr217.78
ARS$43,786.41
List Price:  ARS$61,304.48
You save:  ARS$17,518.06
Bs347.54
List Price:  Bs486.59
You save:  Bs139.04
COP$198,222.27
List Price:  COP$277,527.04
You save:  COP$79,304.77
₡25,463.28
List Price:  ₡35,650.64
You save:  ₡10,187.35
L1,237.47
List Price:  L1,732.56
You save:  L495.08
₲373,144.52
List Price:  ₲522,432.19
You save:  ₲149,287.66
$U1,931.55
List Price:  $U2,704.33
You save:  $U772.77
zł201.47
List Price:  zł282.07
You save:  zł80.60
Already have an account? Log In

Transcript

Working with SQL queries, what follows is merely a taste on the topic of SQL. It is not the intention to cover the subject fully, since you would need to read not one, but several books. competency will take a lot of practice many hours, possibly months. There are a lot of job positions available for SQL programmers, even if you only know Microsoft Access, and there are quite a number of other databases on the market opportunities are unlimited. Which on customer table, there were only two records. I've increased the size so it looks more like a live situation.

I'll double click on customer and see how many more I've had it and quite a few. So here are all of the records that I've entered. Now you may be asking how did I do this? Well, if your answer was probably by me In an existing customer Excel spreadsheet, you are correct. Now that we have generated tables imported data into the customer table and laid it into the order table, we can now begin working with a wide range of queries by using Microsoft SQL access. First, let's open the access query window.

And the way that we do that is by clicking on and what it will do first is remove that table from my view from my navigational view. And I'll click on query wizard. And here is a dialog box asking what sort of a query do we want? We want a simple, open or simple query wizard and asked me what fields do I want to view in this query. I will select ID followed by last name and using the forward arrow and then first name And then perhaps I will go with city. And that's sufficient for the first query.

Click Next. And what I will select here is a detail summary. Click Next. So what title we want to call this query, I'll change it to customer query one, and finish. And here is the result. So a listing from a customer table, have the ID, the last name, followed by the first name, followed by the city.

Save this as customer query one, but let's just ensure and click the Save icon. And now we'll start another query. So let's return back to the splash screen. And what we will do is select a customer order database again, remove this from our navigation pane. And What I'm going to use is the customer query one, but be a little more selective in my query. So I'll double click this.

And what we want is perhaps a selection. First of all, not all of the fields, but just on Kingston. So I am looking for a city where we can find Kingston and locate this. And there it is. As far as this course is concerned, we are now finished with a query wizard. And what I would like to do is to move on to Query Design.

I'll click Create again and select Query Design. Looking at the customer table for now only and we'll look at the order table or join those two together later. I'll add that to my navigational And close of the show table dialog. I will now go to home and view. What I propose doing here is looking at SQL statements in the flesh and seeing if we can manipulate some of these SQL statements ourselves. So I'll go into the SQL View.

And what pops up is really two statements, a select statement, and a from statement. Each one has a purpose, and I'll explain. The SELECT statement specifies what fields you want viewed in your query. So if I put in select last name, comma first name comma address, those fields then would be queried in the values for the customer table. As shown here, the from statement is followed by a table name, and in our case, a customer table. Well when we added a table In the show table, we select a customer.

So notice how that one popped up. There is one other statement I would like to include which is very common in SQL. And it's the where statement. The where statement specifies the criteria under which the SELECT FROM is going to operate. So if I selected a number of columns from a table, the work could specify any conditions under which this will operate. And what I will do is I will select all of the fields in the customer table and instead of writing out each one of the fields, and asterik will suffice to indicate that I want to select everything in the customer table all the fields.

I condition are built in is where city is too, and in this case, so we'll pick Hamilton, followed by an asteroid. have to be very careful because the indicator here is that Hamilton has to be in quotes. And if it's text base it does. And the final ending of select from where it has to be suffixed with a semicolon. I'm going to save that. It asked me for the for the query name and I will call it customer query to see okay, and it pops up in the object pane.

So I have the customer query two in the object pane, which is comprised of three statements select from where, and the specification is to select all, but restricted to only where the city is equal to Hamilton. So we've saved it as customer query to, I will remove this from the navigation pane and double click and see what the result is from this query. Great. So we have all the fields shown, but only two rows given based on the condition where the city is equal to Hamilton. We could do similar operations with the order table. But instead How about a query based on joining two tables together, the customer and the order table will repeat some of the steps that we did in the last query by going to the Create Query Design.

And this time instead of just one table, let's select two so we'll add the customer table. And we'll also now include the order table. close off this dialog box. We want these two tables to be joined on customer ID that will select from the customer table. I'm holding down the left mouse and holding it until I reach the customer ID in the order table and then release it. What appears is a relation line, which I will right click and join the two together.

The join Properties dialog box comes up and we want from this join properties all only those rows which are joined and common between the two fields, the two common fields ID and customer ID. Okay them. Down here in this navigation part, we want to specify the fields that we want to see in the queries I want to select a couple. In the customer table. I'm going to select the first name and the last name maybe a couple of columns The order table. So in the order table, I want the order ID.

And how about the order notes of order notes. I want to save them Ctrl S also will do, I will call it join query one. Okay, it closes off. And we know by double clicking, we now have the joint query and the object pane. If double, if we double click it, we should get the results of the query that we just created. And there it is.

Always possibility occurs that we need to modify not only the join query but any of the queries that we created. If we highlight to focus on this particular case, a joint query and hit the right key, we can go into the design view make any modifications that we did previously, so perhaps we want to add another field. Here. We want the order city. And the criteria is Hamilton. Let's see how that works out.

We'll save it. And we'll clear this pain off and double click another query that is most useful a parameter query. You select a previously saved query. And in my case, customer query one, enter into the design view and specify a parameter based on a criteria you want and the criteria will be for the user to enter a city and executing the particular query call query number one, based on this criteria that we just specified. So let's try that. First of all, save it.

Play this pain out. And I'll double click No customer query and see what happens. Ah. So, the parameter query now executes and it asks you for a city. State nice Niagara and executed. And it picks up rows where the city is equal to Niagara.

I do hope you've enjoyed this session on Microsoft Access SQL. And there was so much more you can do with it. Much literature has been written on the subject of sequel At least you now have an initial understanding and can explore further. I would like to encourage you to go further and dig deeper into the topic.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.