473,656 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Left Outer Join with Where clause

155 New Member
I can't seem to get this working:

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT c.c_id,c.c_name, COUNT( p.recipe_title ) as theCount
  2. FROM new_recipe_cat AS c
  3. LEFT OUTER JOIN new_recipes AS p ON c.c_id = p.c_id
  4. WHERE (c_id==11 && c_id==12 && c_id==13 && c_id==14
  5. && c_id==15 && c_id==16 && c_id==17 && c_id==22
  6. && c_id==23)
  7. AND r_allow=1
  8. GROUP BY c.c_name";
The where clause isn't working and it's throwing an error: Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource

Any ideas on how I can fix this?

Thanks
Feb 5 '10 #1
4 2284
Markus
6,050 Recognized Expert Expert
Get the error string from mysql by using mysql_error().
Feb 5 '10 #2
Atli
5,058 Recognized Expert Expert
Yep, you should always check mysql_error() when there is an error in a MySQL query.

However, I would guess that your problem is with the "c_id==11" checks. There is only supposed to be a single "=" in there. SQL does not use two "=" chars like most programming languages do.
Feb 5 '10 #3
DavidPr
155 New Member
However, I would guess that your problem is with the "c_id==11" checks. There is only supposed to be a single "=" in there. SQL does not use two "=" chars like most programming languages do.
Right, I was working with an if clause earlier and the two == was stuck in my mind.

I tried a few various ways of working the WHERE clause but it just wasn't doing it for me. I used the mysql_error, but it wasn't throwing an error. It just didn't return anything or something that I didn't want. Oh well, I just went back to using an if clause. It list what I want just not in alphabetical order.

I appreciate all the help. Thanks.

DavidPr
Feb 9 '10 #4
Atli
5,058 Recognized Expert Expert
No problem.

One thing that I don't get though. You used && (and) between all those checks. Are you sure you didn't mean to use || (or)? - Using && your c_id would have had to match all of the numbers per row to return it (which doesn't make sense. Presumably it only has one value).

You could try the IN() function. - Something like:
Expand|Select|Wrap|Line Numbers
  1. WHERE c_id IN(11, 12, 13, 14, 15, 16, 17, 22, 23)
Feb 9 '10 #5

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

Similar topics

3
2281
by: sks | last post by:
I have a Product table, a Categories table and a join table that contains product to category mappings (each product can be in many categories) CREATE TABLE categories ( id bigint(20) unsigned NOT NULL auto_increment, name varchar(255) NOT NULL default '', site_id bigint(20) NOT NULL default '0', PRIMARY KEY (id), ) TYPE=MyISAM;
1
4209
by: Steve | last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three "Left Outer Joins" in order to return every transaction for a specific set of criteria. Using three "Left Outer Joins" slows the system down considerably. I've tried creating a temp db, but I can't figure out how to execute two select commands. (It throws the exception "The column prefix 'tempdb' does not match with a table name or alias name used in the query.")
3
23087
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but he doesn't know how to do that, or even if he can, and i don't have to time to learn DB2 from scratch right now. The following SQL Query is a trimmed sample of the full View (i.e. Logical) definition - and i would create it on an SQL based...
5
2288
by: Dev | last post by:
Hello all, I need to do a left out join where a.field1 ilike %b.field2% But I can not figure out the exact syntax to using the ilike in the join? ----------
2
3138
by: tricard | last post by:
Good day all, I have a large outer joined query that I want to have some criteria. The select query is gathering all part numbers from tblPartNumbers, left joining to tblPartNumberVendor (since more than one vendor can make the part), then left joining to tblPartNumberSupplier (since more than one supplier can distribute the vendor's part), then left joining to tblPartNumberCost (since more than one cost can be associated with a single...
1
4561
by: Eitan M | last post by:
Hello, I want to do select like this : select t1.col_2 from table_1 t1, table_2 t2 where t1.col_1 = t2.col_1 (+) The above is correct syntax for Oracle. What is the correct syntax for access. (Not the syntax : left outer join table_1 on table_2 etc... , but something
9
9216
by: shanevanle | last post by:
I have two tables that are pretty big. I need about 10 rows in the left table and the right table is filtered to 5 rows as well. It seems when I join the tables in the FROM clause, I have to filter my left table in the WHERE clause and cannot filter it in the FROM clause. This seems like it would cause a lot of overhead especially when my left table is ten thousand rows. Am I wrong in thinking that the two tables get joined with the...
5
15496
by: Sascha.Moellering | last post by:
Hi, I receive the error code SQL0338N if I try to compile this statement (part of the statement): .... left outer join lateral (SELECT * FROM LIZSYSABA.VWZL0359TBS WHERE tbs_name = CASE WHEN MC.type_txt = 'ZAB' THEN 'BII' ELSE 'STD' END) AS TB1 on CASE WHEN MC.fixed_date_dat IS NULL THEN cast('01.01.2007' as date) + MC.rel_shift_NR DAY ELSE MC.fixed_date_dat END
3
19226
by: pbassutti | last post by:
Hello, I'm trying to link two tables... one for Employees and the other for Timecards I need to get a list of employees that do not have timecards on an SPECIFIC DATE I tried the follonwing
9
11915
by: shapper | last post by:
Hello, I am used to SQL but I am starting to use LINQ. How can I create Left, Right and Inner joins in LINQ? How to distinguish the different joins? Here is a great SQL example: http://www.codinghorror.com/blog/archives/000976.html
0
8380
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8816
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8710
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6162
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
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
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
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.