Hi
I have two tables
TABLE1
t1_id int not null
t1_other stuff blah blah
TABLE2
t2_id int not null
t2_t1_id int not null
t2_other stuff blah blah
the link between the tables is t1_id --> t2_t1_id
There is a list of items with ID 1-10 in TABLE1
in TABLE2 there is a list of items with the t2_t1_id 1-5
What I want to do is select stuff from TABLE1 because they don't have an
entry in TABLE2 i.e. 6-10
Can this be done?
Thanks in advance
Eurisko 6 1510
Yes,
your tables both needs to be of the InnoDB type (not MYISAM !),
and you need to use:
ALTER TABLE `table2`ADD CONSTRAINT `table2_ibfk1` FOREIGN KEY (`td2_id`)
REFERENCES `table1` (`td1_id`) ON UPDATE CASCADE;
Or someting alike.
Look for documentation about FOREIGN KEY
(in google search for: foreign key mysql )
Ciao,
Wouter
"Elpetha Brooke" <ns*********@ntlworld.com> wrote in message
news:Bw**************@newsfe6-win.ntli.net...
: Hi
:
: I have two tables
:
: TABLE1
: t1_id int not null
: t1_other stuff blah blah
:
: TABLE2
: t2_id int not null
: t2_t1_id int not null
: t2_other stuff blah blah
:
: the link between the tables is t1_id --> t2_t1_id
:
: There is a list of items with ID 1-10 in TABLE1
: in TABLE2 there is a list of items with the t2_t1_id 1-5
:
: What I want to do is select stuff from TABLE1 because they don't have an
: entry in TABLE2 i.e. 6-10
:
: Can this be done?
:
: Thanks in advance
:
: Eurisko
:
:
Thanks Wouter, but what sql statement would acheive my goal
Thanks again
Eurisko
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl... Yes,
your tables both needs to be of the InnoDB type (not MYISAM !), and you need to use:
ALTER TABLE `table2`ADD CONSTRAINT `table2_ibfk1` FOREIGN KEY (`td2_id`) REFERENCES `table1` (`td1_id`) ON UPDATE CASCADE;
Or someting alike. Look for documentation about FOREIGN KEY (in google search for: foreign key mysql )
Ciao, Wouter
"Elpetha Brooke" <ns*********@ntlworld.com> wrote in message news:Bw**************@newsfe6-win.ntli.net... : Hi : : I have two tables : : TABLE1 : t1_id int not null : t1_other stuff blah blah : : TABLE2 : t2_id int not null : t2_t1_id int not null : t2_other stuff blah blah : : the link between the tables is t1_id --> t2_t1_id : : There is a list of items with ID 1-10 in TABLE1 : in TABLE2 there is a list of items with the t2_t1_id 1-5 : : What I want to do is select stuff from TABLE1 because they don't have an : entry in TABLE2 i.e. 6-10 : : Can this be done? : : Thanks in advance : : Eurisko : :
Elpetha Brooke wrote: What I want to do is select stuff from TABLE1 because they don't have an entry in TABLE2 i.e. 6-10
SELECT TABLE1.*
FROM TABLE1 LEFT OUTER JOIN TABLE2 ON TABLE1.t1_id = TABLE2.t2_t1_id
WHERE TABLE2.t2_t1_id IS NULL
Regards,
Bill K.
Thanks Bill That did the trick ;)
Eurisko
"Bill Karwin" <bi**@karwin.com> wrote in message
news:cm*********@enews1.newsguy.com... Elpetha Brooke wrote: What I want to do is select stuff from TABLE1 because they don't have an entry in TABLE2 i.e. 6-10
SELECT TABLE1.* FROM TABLE1 LEFT OUTER JOIN TABLE2 ON TABLE1.t1_id = TABLE2.t2_t1_id WHERE TABLE2.t2_t1_id IS NULL
Regards, Bill K.
"Wouter" <no******************@djwice.com> wrote in message
news:cm**********@news.tudelft.nl... Yes,
your tables both needs to be of the InnoDB type (not MYISAM !), and you need to use:
ALTER TABLE `table2`ADD CONSTRAINT `table2_ibfk1` FOREIGN KEY (`td2_id`) REFERENCES `table1` (`td1_id`) ON UPDATE CASCADE;
Or someting alike. Look for documentation about FOREIGN KEY (in google search for: foreign key mysql )
Ciao, Wouter
Why would he need to change is table type to InnoDB? Why not just use an
outer join?
Yes, I was to quick in my responds.
The join that Bill did suggest is the way to do it.
I only read;
I want table1_id -> table2_id
and so wrote the alter table responds, way to quick ;)
Wouter
"Phillip T. Murphy" <pS**********@bellsouth.net> wrote in message
news:AV****************@bignews5.bellsouth.net...
:
: "Wouter" <no******************@djwice.com> wrote in message
: news:cm**********@news.tudelft.nl...
: > Yes,
: >
: > your tables both needs to be of the InnoDB type (not MYISAM !),
: > and you need to use:
: >
: > ALTER TABLE `table2`ADD CONSTRAINT `table2_ibfk1` FOREIGN KEY (`td2_id`)
: > REFERENCES `table1` (`td1_id`) ON UPDATE CASCADE;
: >
: >
: > Or someting alike.
: > Look for documentation about FOREIGN KEY
: > (in google search for: foreign key mysql )
: >
: > Ciao,
: > Wouter
: >
: >
: Why would he need to change is table type to InnoDB? Why not just use an
: outer join?
:
: This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gordon |
last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to
delete rows from t1 based on criteria on the t table and a relationship
between t ad t1 (in this case the id column). In the...
|
by: Lenz Grimmer |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
MySQL 4.0.14, a new version of the popular Open Source/Free Software
Database, has been released. It is now available in source and binary...
|
by: Philip Stoev |
last post by:
Hi all,
Please tell me if any of this makes sense. Any pointers to relevant
projects/articles will be much appreciated.
Philip Stoev
http://www.stoev.org/pivot/manifest.htm
...
|
by: Mike Chirico |
last post by:
Interesting Things to Know about MySQL
Mike Chirico (mchirico@users.sourceforge.net)
Copyright (GPU Free Documentation License) 2004
Last Updated: Mon Jun 7 10:37:28 EDT 2004
The latest...
|
by: jlee |
last post by:
I'm pretty much a newbie on mysql, and I need some help.
I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4
(i386) on a server hosting an active website.
The site's developer...
|
by: |
last post by:
Hello...
i have a table which contains a column named "ask" and a column named
"per"...
my think is that i want to search in "ask" and echo the data stored in "per"
for this entry...
How do i do...
|
by: Atli |
last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users.
Anyone should be able to get...
|
by: janetopps |
last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
|
by: ssnaik84 |
last post by:
Hi Guys,
Last year I got a chance to work with R&D team, which was working on DB scripts conversion..
Though there is migration tool available, it converts only tables and constraints..
Rest of...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |