?
Solved

MYSQL - Query Select

Posted on 2011-05-13
8
Medium Priority
?
392 Views
Last Modified: 2012-05-11
hi,

I have 2 tables

TABLE_NAME = VENDUTI

FIELDS:

IDARTICOLO: INTEGER
QUANTITA: INTEGER


TABLE_NAME = ARTICOLI

FIELDS:

ID: INTEGER
DESCRIZIONE: VARCHAR

I need a query that makes me see all the records in the table articoli that are not present in the table
venduti
0
Comment
Question by:danz67
8 Comments
 
LVL 23

Accepted Solution

by:
Rajkumar Gs earned 500 total points
ID: 35752388
SELECT * FROM VENDUTI WHERE IDARTICOLO NOT IN
(SELECT ID FROM ARTICOLI)

Open in new window

OR

SELECT A.*
FROM VENDUTI  A
LEFT OUTER JOIN ARTICOLI B OB A.IDARTICOLO  = B.ID
WHERE B.ID IS NULL

Open in new window


Assuming that IDARTICOLO  joins with ID in second table
I think, secod one will be more faster
0
 
LVL 1

Expert Comment

by:phutsa
ID: 35752417
The first one is easy for understanding but it's slowy than second.
0
 

Author Comment

by:danz67
ID: 35752457
SELECT A.*
FROM VENDUTI  A
LEFT OUTER JOIN ARTICOLI B OB A.IDARTICOLO  = B.ID
WHERE B.ID IS NULL


generate error
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:danz67
ID: 35752476
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OB A.IDARTICOLO  = B.ID
WHERE B.ID IS NULL' at line 3
0
 
LVL 41

Expert Comment

by:Sharath
ID: 35752486
>> generate error

What is the error?
0
 

Author Comment

by:danz67
ID: 35752819
The error is:


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OB A.IDARTICOLO  = B.ID
WHERE B.ID IS NULL' at line 3
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 35753129
Simple mistake. 'OB' should be renamed to 'ON' !!
SELECT A.*
FROM VENDUTI  A
LEFT OUTER JOIN ARTICOLI B ON A.IDARTICOLO  = B.ID
WHERE B.ID IS NULL

Open in new window

0
 
LVL 5

Expert Comment

by:kumaresan2011
ID: 35753325
Hi

Use this querys..

SELECT VENDUTI.*,ARTICOLI .*
FROM VENDUTI ,ARTICOLI  WHERE  ARTICOLI.ID  = VENDUTI.IDARTICOLO

OR

SELECT VENDUTI.*,ARTICOLI .*
FROM VENDUT JOIN ARTICOLI  ON( ARTICOLI  .IDARTICOLO  = VENDUT .ID)

OR

SELECT VENDUTI.*,ARTICOLI .*
FROM VENDUT LEFT OUTER JOIN ARTICOLI  ON( ARTICOLI  .IDARTICOLO  = VENDUT .ID)

OR

SELECT VENDUTI.*,ARTICOLI .*
FROM VENDUT INNER JOIN ARTICOLI  ON( ARTICOLI  .IDARTICOLO  = VENDUT .ID)

any one join query will satisfy u r needs

by
kumaresan

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question