473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

May I know what does this sentence do "select * from category c left join"

Hi,I'm new to PHP...I currently doing a PHP project....I don't understand this code..can someone please kindly explain to me..Thanks

select * from category c left join category2 c2 on c2.cat1_id=c.cat_id where c.cat_id=" . $_GET['cate1'] . " and c2.cat2_id=" . $_GET['cate2']

What does the c & c2 do?
& what is the output result?

Here the database table:

CREATE TABLE `category` (
`cat_id` bigint(20) NOT NULL auto_increment,
`cat_name` varchar(200) NOT NULL default '',
PRIMARY KEY (`cat_id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;


CREATE TABLE `category2` (
`cat2_id` bigint(20) NOT NULL auto_increment,
`cat1_id` bigint(20) NOT NULL default '0',
`cat2_name` varchar(200) NOT NULL default '',
PRIMARY KEY (`cat2_id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;
Sep 25 '06 #1
1 1643
steven
143 100+
Hi,I'm new to PHP...I currently doing a PHP project....I don't understand this code..can someone please kindly explain to me..Thanks

select * from category c left join category2 c2 on c2.cat1_id=c.cat_id where c.cat_id=" . $_GET['cate1'] . " and c2.cat2_id=" . $_GET['cate2']

What does the c & c2 do?
& what is the output result?

Here the database table:

CREATE TABLE `category` (
`cat_id` bigint(20) NOT NULL auto_increment,
`cat_name` varchar(200) NOT NULL default '',
PRIMARY KEY (`cat_id`)
) TYPE=MyISAM AUTO_INCREMENT=6 ;


CREATE TABLE `category2` (
`cat2_id` bigint(20) NOT NULL auto_increment,
`cat1_id` bigint(20) NOT NULL default '0',
`cat2_name` varchar(200) NOT NULL default '',
PRIMARY KEY (`cat2_id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;

The c and c2 that you can see are "aliases". An alias is just an alternative name for something. In the case of your statement, c and c2 are the shorthand aliases given to the tables category and category2. This is done to make the statements shorter. It just makes it easier to type / follow. You don't have to constantly type out long table names (and in some queries, you might need to type them out many times!!)

Note, you only need to use aliases on queries that call more than one table, so you can differentiate between the different fields between the tables.

Eg, if both tables have an 'id' field, you would do "SELECT c.id, c2.id FROM category AS c, category2 AS c2".

It's also good practice to use the AS keyword to state aliases, although it's not compulsary, it makes more sense.

You don't seem to know much about the code... is this a school assignment or homework?

A good place to start learning sql... http://w3schools.com/sql/
Sep 26 '06 #2

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

Similar topics

16
by: lkrubner | last post by:
Are there any benchmarks on how much an extra, unneeded VARCHAR, CHAR, INT, BIGINT, TEXT or MEDIUMTEXT slows down a database call with MySql? PostGre info would also be useful. I'm trying to...
7
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"...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
1
by: Neil H | last post by:
Hi All I am doing a multiple table and field database search, and my problem lies in the options that a user has. In each field, the user can specify a specific value or any value. I take each...
2
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
0
by: Juan Irigoyen | last post by:
How I can traduce this sentence in VB. Thanks. Dim arrSesions As DataRow() arrSesions = Context.Cache("SessionKeys").Select("xxx")
11
by: bcurtu | last post by:
Hi, I have a BIIIIIG problem with the next query: cursor.execute(""" SELECT titem.object_id, titem.tag_id FROM tagging_taggeditem titem WHERE titem.object_id IN (%s) """,( eid_list))
0
by: CatchSandeepVaid | last post by:
Product and ProductBasic has one-to-one relationship Product ---> ProductID <<PK>> ProductBasic ----> ProductId, useCode, StartTime as composite key..... this startTime's value will be known as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...

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.