<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ramani Hitesh (iOS Software Engineer)</title>
    <description>The latest articles on DEV Community by Ramani Hitesh (iOS Software Engineer) (@ramanihitesh).</description>
    <link>https://dev.to/ramanihitesh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F620948%2F4bd1b5a6-e5d6-4c86-b13c-2fc922846183.jpeg</url>
      <title>DEV Community: Ramani Hitesh (iOS Software Engineer)</title>
      <link>https://dev.to/ramanihitesh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ramanihitesh"/>
    <language>en</language>
    <item>
      <title>SQL Most Important Query</title>
      <dc:creator>Ramani Hitesh (iOS Software Engineer)</dc:creator>
      <pubDate>Mon, 26 Apr 2021 06:56:05 +0000</pubDate>
      <link>https://dev.to/ramanihitesh/sql-most-important-query-4fhh</link>
      <guid>https://dev.to/ramanihitesh/sql-most-important-query-4fhh</guid>
      <description>&lt;p&gt;MySql&lt;/p&gt;

&lt;p&gt;To see the databases&lt;/p&gt;

&lt;p&gt;1)show databases;&lt;/p&gt;

&lt;p&gt;to create database&lt;/p&gt;

&lt;h2&gt;
  
  
  2)create database cognizantstud;
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;to goto the database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  3)use cognizantstud;
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;to drop database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  4)drop database cognizantstud;
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;to create a table
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;5)create table student&lt;/p&gt;

&lt;p&gt;( studid int not null auto_increment,&lt;br&gt;
   name varchar(30) not null,&lt;br&gt;
   address varchar(30) not null,&lt;br&gt;
   primary key(studid));&lt;/p&gt;




&lt;p&gt;6)to insert record&lt;/p&gt;

&lt;h2&gt;
  
  
  insert into student values(101,'tarun','chennei');
&lt;/h2&gt;

&lt;p&gt;7)to view the records &lt;/p&gt;

&lt;h2&gt;
  
  
  select * from student;
&lt;/h2&gt;

&lt;p&gt;8)update the record&lt;/p&gt;

&lt;h2&gt;
  
  
  update student set address='Bangalore' where name='tarun';
&lt;/h2&gt;

&lt;p&gt;9)to create a view (view will not contain any data.it will contain only the query)&lt;br&gt;
create view stud as select studid,name from student;&lt;/p&gt;

&lt;h2&gt;
  
  
  we can do insert,update and delete of the view it will replect to the base table.
&lt;/h2&gt;

&lt;p&gt;10)to see all the tables and views&lt;/p&gt;

&lt;h2&gt;
  
  
  show tables;
&lt;/h2&gt;

&lt;p&gt;11)where condition :-&lt;/p&gt;

&lt;h2&gt;
  
  
  select * from student where name='tarun';
&lt;/h2&gt;

&lt;p&gt;12)distinct :-(unique data will be displayed)&lt;/p&gt;

&lt;h2&gt;
  
  
  select distinct address from student;
&lt;/h2&gt;

&lt;p&gt;13)order by:-&lt;br&gt;
select * from student order by name;&lt;br&gt;
select * from student order by name asc;&lt;/p&gt;

&lt;h2&gt;
  
  
  select * from student order by name desc;
&lt;/h2&gt;

&lt;p&gt;14)group by&lt;/p&gt;

&lt;h2&gt;
  
  
  select address, count(*) from student group by address;
&lt;/h2&gt;

&lt;p&gt;15)aggregate function&lt;/p&gt;

&lt;h2&gt;
  
  
  count(),sum(),avg(),min(),max(),first(),last()
&lt;/h2&gt;

&lt;p&gt;i)select count(*) from student;&lt;br&gt;
first record  :- select name from student limit 1;&lt;/p&gt;

&lt;h2&gt;
  
  
  last record :-select name from student order by name desc limit 1;
&lt;/h2&gt;

&lt;p&gt;16)alter table:-&lt;br&gt;
alter table student add salary int not null;&lt;br&gt;
to add data to salary column :-&lt;br&gt;
update student set salary=45000 where studid=101;&lt;/p&gt;

&lt;h2&gt;
  
  
  update student set salary=35000 where studid in (102,103,104);
&lt;/h2&gt;

&lt;p&gt;17)select sum(salary) from student;&lt;br&gt;
18)select avg(salary) from student;&lt;br&gt;
19)select min(salary) from student;&lt;/p&gt;

&lt;h2&gt;
  
  
  20)select max(salary) from student;
&lt;/h2&gt;

&lt;p&gt;between and example:-&lt;/p&gt;

&lt;h2&gt;
  
  
  21)select * from student where salary between 30000 and 46000;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  like % (wildcard)
&lt;/h2&gt;

&lt;p&gt;22)select * from student where name like 'p%';(word starting with p will display)&lt;/p&gt;

&lt;h2&gt;
  
  
  select * from student where name like '%r';(word ending with r will display)
&lt;/h2&gt;

&lt;p&gt;23)truncate table:-&lt;br&gt;
it will delete all the data from the table.&lt;/p&gt;

&lt;h2&gt;
  
  
  truncate table student;
&lt;/h2&gt;

&lt;p&gt;24)drop table;&lt;br&gt;
it will delete the data as well as the table also.&lt;/p&gt;

&lt;h2&gt;
  
  
  drop table student;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  25)join
&lt;/h2&gt;

&lt;p&gt;create table marks&lt;br&gt;
(studid int(4),&lt;br&gt;
phy int(4),&lt;br&gt;
chem int(4),&lt;br&gt;
maths int(4),&lt;br&gt;
tot int(4),avg int(4));&lt;/p&gt;

&lt;p&gt;i)insert into marks(studid,phy,chem,maths) values(101,56,67,78);&lt;br&gt;
ii)update marks set tot=(phy+chem+maths) where studid in (101,102,103);&lt;/p&gt;

&lt;h2&gt;
  
  
  iii)update marks set avg=tot/3 where studid in (101,102,103);
&lt;/h2&gt;

&lt;h2&gt;
  
  
  joining 2 tables:-
&lt;/h2&gt;

&lt;p&gt;select a.studid,a.name,a.address,a.salary,b.phy,b.chem,b.maths,b.tot,b.avg from student a,marks b where a.studid=b.studid;&lt;/p&gt;

</description>
      <category>database</category>
      <category>sql</category>
      <category>datascience</category>
      <category>news</category>
    </item>
  </channel>
</rss>
