Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php mysql query

Posted on 2013-05-29
3
Medium Priority
?
259 Views
Last Modified: 2013-05-29
Hi, I am not sure if mysql can do this or not but figured I would ask:

1. I have a table with a column with this data point:
bunk = BA3-01B

2. I have a table as boats
column abbreviation = BA3

3. I have a table as bunks
boatID = 1
cabin = 01
bunk = B

Now in my inventory table I have a column called bunks with "BA3-01B"

I want to take "BA3-01B" and search "BA3" on table boats to get the boatID then search boatID, cabin "01" and bunk "B" from table bunks and return table bunks - cabin_type data.

Here is the query I was messing with. It did not error but did not return any results. I think I am on the right track.

SELECT
	`charters`.`boatID`,
	`boats`.`abbreviation`,
	`bunks`.`cabin_type`


FROM
	`inventory`,`charters`,`boats`,`bunks`

WHERE
	`inventory`.`inventoryID` = '9150099'
	AND `inventory`.`charterID` = `charters`.`charterID`
	AND `charters`.`boatID` = `boats`.`boatID`
	AND `boats`.`boatID` = `bunks`.`boatID`
	AND `inventory`.`bunk` = CONCAT(`boats`.`abbreviation` + '-' + `bunks`.`cabin`,`bunks`.`bunk`)

Open in new window

0
Comment
Question by:Robert Saylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39205290
ok, I solved my own question :)

I created a temp table and inserted the char "-" then included that in my concat and the query returned the data I wanted.
0
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 39205349
Did you try this?
SELECT
	`charters`.`boatID`,
	`boats`.`abbreviation`,
	`bunks`.`cabin_type`
FROM
	`inventory`,`charters`,`boats`,`bunks`
WHERE
	`inventory`.`inventoryID` = '9150099'
	AND `inventory`.`charterID` = `charters`.`charterID`
	AND `charters`.`boatID` = `boats`.`boatID`
	AND `boats`.`boatID` = `bunks`.`boatID`
	AND `inventory`.`bunk` = CONCAT(`boats`.`abbreviation`,'-',`bunks`.`cabin`,`bunks`.`bunk`)

Open in new window

0
 
LVL 7

Author Comment

by:Robert Saylor
ID: 39205491
No but I will. I was using the plus like in JavaScript. I bet that would do it as well.

Thanks!
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question