473,573 Members | 4,459 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
  3. WHERE EXISTS (
  4. SELECT * FROM newspaper
  5. WHERE id = car_id
  6. );
Or:

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 2276

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

Similar topics

13
5540
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:
6
3063
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:
4
1646
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
0
1651
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,
0
1376
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')
7
1679
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
4
2136
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...
1
1922
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...
0
1745
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...
0
7661
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...
0
7978
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8167
jinu1996
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...
0
8028
tracyyun
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...
0
6349
agi2029
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...
1
5550
isladogs
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...
0
5252
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...
0
3692
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1263
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.