Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php mysql query

Posted on 2013-05-29
3
Medium Priority
?
260 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
  • 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

916 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