473,695 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looking for help with MySQL 4.0.24 LEFT JOIN

4 New Member
Quick and dirty version.
Godaddy server using MySQL 4.0.24

Iím trying a left join to obtain idís in table A(cars) that are NOT in car_id in table B(newspaper):

*This is a cut down version to simplify testing. Full version is posted towards the end.

Expand|Select|Wrap|Line Numbers
  1. SELECT C.id
  2. FROM cars C LEFT OUTER JOIN newspaper N USING (C.id=N.car_id)
  3. WHERE N.car_id IS NOT NULL;
Iím sure itís just syntax errors as I donít know SQL so well but I canít for the life of me get it working.

Please keep in mind Iím a total noob when it comes to SQL so if you have time please include a SQL code example in your response.


Ok, full story for anyone interested.
Iím trying to compare two vehicle info tables.
One that is a listing of a dealers cars, the other is a listing of the dealers cars currently in our newspaper. Iím using this to populate Ajax drag n drop columns so they can simply drag vehicles into the ďinĒ column and submit them us.

This is the query Iím using in MySQL 5.0 which works fine.

Expand|Select|Wrap|Line Numbers
  1. SELECT c.*, ma.makeName, mo.modelName FROM cars c, makes ma, models mo 
  2. where c.dealer_id=12 and c.make = ma.makeId and c.model = mo.modelId and not exists (
  3. select car_id from newspaper n 
  4. where c.id = n.car_id and n.submit_num =10
  5. );
(Iím sure itís nasty code as itís all pieced together via examples I could find online)

dealer_id and submit_num are variables in the script. I just put the values in for testing / example.

After having issues on our live server I cut it down to itís simplest form to try and figure out exactly what the problem was.

Expand|Select|Wrap|Line Numbers
  1. SELECT id
  2. FROM cars
  4. SELECT * FROM newspaper
  5. WHERE id = car_id
  6. );

Expand|Select|Wrap|Line Numbers
  1. SELECT id FROM cars 
  2. WHERE id IN(
  3. SELECT car_id FROM newspaper
  4. );
I read on php.net that EXISTS is only supported from 4.1 on. And that earlier versions of MySQL should try rewriting the query using a LEFT JOIN.

So I searched a bit and found a query that fits what I need and well, here it is.

Expand|Select|Wrap|Line Numbers
  1. SELECT C.id
  2. FROM cars C LEFT OUTER JOIN newspaper N USING (C.id=N.car_id)
  3. WHERE N.car_id IS NOT NULL;
Iím getting this error.

MySQL said:
Documentation #1064 - 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 '.id=N.car_id)
WHERE N.car_id IS NOT NULL' at line 2
Iíve searched LEFT JOIN on the MySQL docs and just cant see what Iím doing wrong.

Any advice would be greatly appreciated.
Just please keep in mind Iím nearly SQL illiterate so please include an example if you have time.
Nov 17 '06 #1
0 2282

Sign in to post your reply or Sign up for a free account.

Similar topics

by: aaron | last post by:
I have a question about (i think) joining. If I have a table in a database that has this info: key - name - favorite 1 - john - 2 2 - judy - 3 3 - joe - 1 the favorite icecream table is this:
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
by: NotGiven | last post by:
I have two tables, Client and Project, related by clientID. I want to display a table with total CURRENT projects and total COMPLETED projects per client. I'd like for it to show like this: Client Name Current Proj Completed Proj Stan's Dormers 4 12 Larry Lincoln Dealership 2 1
by: rg | last post by:
Hello, I use invisionboard on a bid web site (20 000 visitors each day) But my server has high load average. Could you help me to optimize these select command. 1) SELECT p.*, m.id,m.name,m.mgroup,m.email,m.joined,m.avatar,m.avatar_size,m.posts,m.aim_name,m.icq_number,
by: Phil Powell | last post by:
I have a rather complicated query with a combination of LEFT JOINs and two MATCHES where the first match is non-boolean to get the accurate score, the second to search as boolean: SELECT image.id, image.image_name, (MATCH (image_name, image_alt, image_location_city, image_location_state, image_location_country) AGAINST ('test')
by: Jim | last post by:
I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station. Example of some tables: Titles Stations Station_Titles ------ -------- ------------- id id Station_ID Title StationName Title_ID
by: Diamondback | last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has descriptive information about the widgets while the VERSIONS table contains IDs relating to different iterations of those widgets over the years. The idea is that from any widget in the database you can look forward and backward to see different versions of the widget through the years. Here are the tables: WIDGETS widget_id name
by: cmgmyr | last post by:
Hey All, I'm having a little problem with exporting data from my database. The problem is that the query seems to be too much for PHP and MySQL to handle since it is timing out. I have the timeout set right now at 3 minutes. I can run this in phpMyAdmin and it usually takes 4-5 minuted to complete. I do not want to have to make the client wait that long for this. This is part of an import/export Excel function that I have made. Here is...
by: Scotsman | last post by:
Hi All I have a sticky problem! Its a LEFT JOIN sql statement which works fine in MySQL but not when called in Perl. Any ideas? I have 2 tables: campaigns & companies. I'm trying to join them so that all columns of both tables are returned when 2 fields match across the tables and some additional tests in the first table. It works fine in MySQL but returns an empty set when called in Perl. Is there some limitation in Perl or a better way...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.