Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-27-2012, 02:58 AM   PM User | #1
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
help with this query

I can't figure it out.

Let say I have table1 and table2.

table1 has exam_number, exam_title fields, table2 has exam_number,exam_title fields

Let say the values of the tables are

Code:
Table1
exam_number,  exam_title
 2                      3
 2                      4
 2                      5

Table2
exam_number,  exam_title
 2                     3
 2                     5

What I want to get is table1 row(exam_number,exam_title) values, that does not exist on table2 row. Meaning I should get 2,4 on table1,thanks..
Anishgiri is offline   Reply With Quote
Old 06-27-2012, 03:32 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,451
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
It would be easier if you were to combine the two tables together and just add an extra field to represent whatever caused you to split it into two tables.

You might want to read up on database normalization.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-27-2012, 04:03 AM   PM User | #3
Anishgiri
Regular Coder

 
Join Date: May 2010
Posts: 173
Thanks: 0
Thanked 0 Times in 0 Posts
Anishgiri is an unknown quantity at this point
For simplicity,I did not include all the fields of the two table, it has a purpose why it's like that..
Anishgiri is offline   Reply With Quote
Old 06-27-2012, 02:42 PM   PM User | #4
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
what have you tried?
guelphdad is offline   Reply With Quote
Old 06-27-2012, 07:48 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
SELECT T1.* 
FROM table1 AS T1
LEFT JOIN table2 AS T2
ON ( T1.exam_number = T2.exam_number AND T1.exam_title = T2.exam_title )
WHERE T2.exam_number IS NULL
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:26 PM.


Advertisement
Log in to turn off these ads.